Almost as predicted, you (婉婷) did indeed try to leave a spam comment message. :-(
Thomas Lee's collection of random interesting items, views on things, mainly IT related, as well as the occasional rant
Tuesday, July 13, 2010
A Quiet Word to the Chinese Comment Spammer
Almost as predicted, you (婉婷) did indeed try to leave a spam comment message. :-(
Monday, July 12, 2010
PowerShell Needs a New Approved Verb
I’ve been playing around a bit with the System.Speech namespace, in particular the System.Speech.Synthesis.SpeechSynthesizer class. This class allows you go get the Speech Synthesis engine speak for you. On my workstation, I have just one voice, called Anna. If you look over on my PSHScripts blog, there’s a script to get all of the voices installed on your system.
As you can see from the script, the class is pretty simple, although it’s one that PowerShell loads by default. Once you create a SpeechSynthesizer object, you can then get the installed voices as the script shows. As you can see, on my system, there’s only one loaded voice (Anna). The Speech Synthesizer has another useful class – Speak (well two, the second being SpeakAsync). These methods enable the SpeechSynthesizer object to speak some text.
I’ve written a couple of scripts that will demonstrate these APIs, and I’ll publish these shortly. But in doing so, I realised that the PowerShell Approved Verb list needs a new verb: Speak, which mirrors the Speak method. If you look closely at the approved verb list, there’s no verbs relating to a voice modality, which with the benefit of hindsight, is unfortunate. For Version 3, I think a new verb is needed, which could be Speak (my favourite) or perhaps Say.
Friday, July 02, 2010
PowerShell and XML Element Attributes
I’ve been playing a bit this week with XML and PowerShell. As you no doubt know, PowerShell has first class XML support built in. To see more about that, see Tobias’s Ebook Chapter on XML and PowerShell. My task this week was to work with attributes that can appear inside an XML tag. I was using the .NET XML class System.XML.XMLElement and it’s various attribute related method.
An XML Element, as noted in MSDN, is a node in a DOM (XML) document. These elements can have attributes which you can associate with the element. For example, consider the following XML element:
<book genre='novel' ISBN='1-861001-57-5'>
<title>Pride And Prejudice</title>
</book>"
Such an element would normally be part of a much larger collection (eg <books></books>), but for the purposes of playing with element attributes, you can load it and then treated as an XML document with elements (albeit not many). You can load this document like this (and yes, there are a bunch more ways!)
$Doc = New-Object System.Xml.XmlDocument
$Doc.LoadXml("<book genre='novel' ISBN='1-861001-57-5'>" +
" <title>Pride And Prejudice</title>" +
"</book>" )
In the XML document, the book element has two attributes, genre and ISBN. Each attribute has the simple format (in the XML) of <attribute name>=<attributevalue>.
Once you load the document, you can do things like:
- Check whether an element has a particular named attribute
- Get the value of an attribute
- Remove an attribute
- Set and attribute
To do this in PowerShell you would do something like this, e.g. to set an attribute:
$Root = $Doc.DocumentELement
$Root.SetAttribute("attributename","value")
In richer XML scripts the attributename and the value would be held in a variable (that you in turn might have obtained from another XML document).
I’ve written several sample scripts over on the PowerShell scripts blog, which re-implement a number of MSDN attribute handling C# samples:
- Get-XMLAttribute.ps1 – this script loads the XML then checks to see if the element has an attribute and if so, the code prints out the value of the attribute.
- Remove-XMLAttribute and Remove-XMLAttributeAt.ps1 – these scripts load the XML and then remove the attribute, but using different .NET methods (i.e. RemoveAttribute and RemoveAttributeAt). Using the Remove AttributeAt, where you specify the position of the attribute, and not the name, is potentially dangerous. I have the t-shirt on that one!
- Set-XMLAttribute.ps1 – this script as the name might imply, loads the XML and adds an attribute to the element.
Fun stuff!
PowerShell and XML Element Attributes
I’ve been playing a bit this week with XML and PowerShell. As you no doubt know, PowerShell has first class XML support built in. To see more about that, see Tobias’s Ebook Chapter on XML and PowerShell. My task this week was to work with attributes that can appear inside an XML tag. I was using the .NET XML class System.XML.XMLElement and it’s various attribute related method.
As noted in MSDN, are a node in a DOM (XML) document. These elements can have attributes which you can associate with the element. For example, consider the following XML element:
<book genre='novel' ISBN='1-861001-57-5'>
<title>Pride And Prejudice</title>
</book>"
Such an element would normally be part of a much larger collection (et <books></books>), but for the purposes of playiing with element attributews, you can load it and then treated as an XML document with elements (albeit not many). You can load this document like this (and yes, there are a bunch more ways!)
$Doc = New-Object System.Xml.XmlDocument
$Doc.LoadXml("<book genre='novel' ISBN='1-861001-57-5'>" +
" <title>Pride And Prejudice</title>" +
"</book>" )
In the XML document, the book element has two attributes, genre and ISBN. Each attribute has the simple format (in the XML) of <attribute name>=<attributevalue>.
Once you load the document, you can do things like:
- Check whether an element has a particular named attribute
- Get the value of an attribute
- Remove an attribute
- Set and attribute
To do this in Powershell you would do something like this, eg to set an attribute:
$Root = $Doc.DocumentELement
$Root.SetAttribute("attributename","value")
In richer XML scripts the attributename and the value would be held in a variable (that you in turn might have obtained from another XML document).
I’ve written several sample scripts over on the PowerShell scripts blog, which re-implement a number of MSDN attribute handling C# samples:
- Get-XMLAttribute.ps1 – this script loads the XML then checks to see if the element has an attribute and if so, the code prints out the value of the attribute.
- Remove-XMLAttribute and Remove-XMLAttributeAt.ps1 – these scripts load the XML and then remove the attribute, but using different .NET methods (i.e. RemoveAttribute and RemoveAttributeAt). Using the Remove AttributeAt, where you specify the position of the attribute, and not the name, is potentially dangerous. I have the t-shirt on that one!
- Set-XMLAttribute.ps1 – this script as the name might imply, loads the XML and adds an attribute to the element.
Fun stuff!
Wednesday, June 30, 2010
They Called Their Web Site WHAT????
Those nice folks at Angel Internet Press sent me a copy of new book: Slurls – They Called Their Website WHAT?!” which has been keeping me amused. A slurl is made up term – joining ‘slur’ and ‘url’. A slurl is a web site URL that can be read in ways other than what the owner probably intended. Slurls come about when someone creates a website name based on their company, but where the words can be read in a much more amusing, and often embarrasing, way! Some of the more amusing slurls are:
- Pen Island, a company making custom pens created: www.penisland.net
- Lumberman’s Exchange, a site for lumberjack equipment created: www.lumberbacksexchange.com (this was later removed)
- Speed of Art, and advertising web site created: www.speedofart.com
- Old Man’s Haven a site for renting cabins in Ohio, created www.oldmanshaven.com
- PowerGen Italia created my favourite: www.powergenitalia.co.it, although this too was later removed and has been obtained by an unrelated individual!
The book lists a number more slurls – most of them quite amusing. I still can’t quite work out just how someone really did create all these web sites and didn’t notice the potential gaff! The author’s website, www.slurls.com shows the SLUR of the day (today, it’s google.co.ck which still has me chuckling) and has discussion forums where you can suggest a SLURL and learn of those that have ceased to be. The web site also has screen shots of the site to show it’s not just a made up url, for example this page pointing to an MP3 site: www.mp3shits.com (MP3’s Hits).
A light read, but highly amusing!
Network Monitor V3.4 Ships
Microsoft has just shipped a new version of Network Monitor, one of my favourite network tools. The new version has a slew of new features. MS has reworked the capturing engine to capture on faster networks without losing frames. The parser logic has been updated giving you the ability to do deeper/slower parsing or shallower/faster parsing, a great feature for fast networks where shallower parsing is acceptable. The UI is also more customisable, something no doubt of value to those who use tools like every day. For a fuller list of features in the new version – see the beta blog announcement here.
Microsoft also provides ongoing information via the Network Monitor blog: here. Additionally, there’s a support forum on the Network Monitor forum. The forums enable you to ask questions about the UI, NMCap, API, parsers and troubleshooting scenarios (and even get answers!).
Sunday, June 20, 2010
PowerShell Plus 3.5 Beta
The beta shows off the new features in V3.5:
- Remoting Support
- Improved Script Sharing
- Enhancements to the code editor
- Enhancements to the Learning Center.
Saturday, June 19, 2010
Another Free PowerShell Book
You can get the English versions of both books here. This is a large-ish ZIP file with both PDF and XPS versions of the book, along with a set of sample scripts. For the German speakers, or at least those who can read German, you can get the original versions here.
Friday, June 18, 2010
PowerShell Script Provider
Just when you think we’ve seen all that the (awesome) PowerShell community can do, along comes another cool development. The latest coolness comes from Oisin Grehan in the form of a PowerShell Script provider. This is a tool, which you can download from Codeplex, that enables you to write a provider purely in script without the need to do stuff in C#. This is pretty cool!.
The project is at version 0.1, with at least 4 more versions planned. As it says on Codeplex, this code is alpha – but knowing Oisin those versions will come quickly.
Thursday, June 17, 2010
Signing PowerShell Scripts – A Gotcha with ISE!
In some enterprise environments, signing PowerShell scripts and setting an execution policy to only run signed scripts is a useful control mechanism. It can avoid less skilled admins ‘fixing’ a script almost correctly and can avoid untested scripts from running. Of course, the malign admin can still cut/paste the scripts into the command line and do damage – but that same admin can nuke the registry, reformat a volume, etc. Script signing is just another layer of defence.
The Scripting Guys Team (well actually superstar MVP Ragnar Harper) has written a two part blog post on the subject of how to do script signing. Part 1 is a useful tutorial on how to setup your own PKI using Windows Server’s built in Certificate Service feature (AD CS as MSFT call it). With Part 1, you learn how to get your code signing digital certificate. Part 2 then talks you through how to use that certificate to generate a signed script.
The demo is good and the instructions work well, however there is one small gotcha. If you use PowerShell ISE to edit and save your scripts, the technique shown in Part 2 will fail. Here’s what you will see (from the ISE).
As you can see, this results in a rather less than helpful “UnknownError”. Turns out the reason is simple: By default, ISE saves scripts in Unicode BigEndian format – which Set-Authenticode does not cater for. And worse, the ISE Save-As dialog does not give you any option to save in a more friendly encoding (ie ASCII!).
There are three solutions to this:
1. Use Notepad to re-save the file as ASCII, then sign it. This is suboptimal but it works.
2. You can get ISE to save as Unicode (not BigEndian) using a small script, unfortunately not from the menus. Just run the following bit of code:
$psise.CurrentFile.Save([system.Text.Encoding]::Unicode)
3: You can get ISE to save as always as ANSI. As t add the following bit of code to your PowerShell ISE:
register-objectevent
$psise
.CurrentPowerShellTab.Files collectionchanged
-action
{
# iterate ISEFile objects
$event
.sender | % {
# set private field which holds default encoding to ASCII
$_
.gettype().getfield(
"encoding"
,
"nonpublic,instance"
).setvalue(
$_
,
[text.encoding]
::ascii)
}
}
Once this fragment is executed, probably by adding it to your Profile, scripts get saved as ANSI and can be signed just fine.
Note in the above, you can both save the current file as ASCII or auto-save as Unicode. Set-AuthenticodeSignature works with both encodings, just not the ISE normal default of Unicode BigEndian (just change ::ASCII to ::UNICODE or vice versa!). Personally, I now save as ASCII. But if you have non-ANSI characters in your scripts, set the default as Unicode!
And a tip of the hat to Oisin Grehan who posted about this on the MVP list and who has posted some of the above code on his blog here.
Thursday, June 10, 2010
Communications Server ‘14’ Powershell Blog Up And Running
The Communications Server ‘14’ team have put up a CS and Powershell blog. You can read it at http://blogs.technet.com/b/csps/. It’s early days, as CS14 was finally revealed to the world (with no NDA!) here in New Orelans TechEd North America. Speaking to the PowerShell PM, the intention is for the blog to be a one-stop shop for all CS14 and PowerShell. I look forward to seeing how this evolves!
Friday, June 04, 2010
Training and the Cloud
I’ve been having some discussions with a client about the impact of cloud computing on the IT training business, particularly IT Professional training. If you believe the hype, cloud computing will take all the problems of running your IT suite and make it a thing of the past. Thus, you don’t need any more IT Pros and therefore no training. Of course it’s nowhere as simple as that! I’ve been reading an interesting blog piece by Alan Le Marquand titled From Servers to Services: the Role for the IT Pro in the Cloud. It’s provided some good input into the training question.
Alan first makes the point that 'the cloud’ is actually many things. Cloud computing has evolved in to distinct layers, each with their own approaches and IT Pro needs. Le Marquand breaks “the cloud” down into three main layers:
- Software as a Service (SaaS)– here you buy the software hosted by a supplier. For example, an organisation can use one of many hosted Exchange solutions for email. For this layer, the hardware, OS layers and application peices are for the most part gone. so IT Pros no longer need to worry about them. Of course, at the application layer, there is still a need to perform management and provisioning functions such as adding or removing email accounts as employees come and go. And since you are paying for the application, you need to monitor your SLA, possibly differently than today as well as manage your supplier.
- Platform as a Service (PaaS)– here the hardware and OS are provided by a supplier but you provide the application – Microsoft’s Azure is an example of this cloud layer. With PaaS, the OS and hardware are primarily managed by the supplier , but you manage the application that sits on top.This layer still requires IT Pros to handle all the application management functions plus the ability to manage the platform in the cloud.
- Infrastructure as a Service (IaaS) – here you just get the hardware provided by the supplier and you deal with the OS, application and everything above. To some degree, this is really not much different than from today in terms of the skills that IT Pros need – the key difference being where you put the hardware and how you scale it out (or not!). IT pros still need to know how to deploy the OS and the applications and manage them. Only the scale is different – you still need to patch, troubleshoot etc.
The role that the IT Professional plays in each of these layers differs, in some cases significantly, from today. And of course, this means training needs differ too. All three layers require you to consider end-user/administration training in how to use and get the most out of the applications. PaaS and IaaS also require you to know how to develop and deploy your application solution. And finally, IaaS requires you to have broadly the same deployment skills as today since most IT Pros start their tasks once the hardware is in place.
The key first step all organisations considering the cloud need to take is to get a good understanding of how to buy as well as deploy and manage cloud services. Organisations are being led to believe by the suppliers that the Cloud is the answer. That may be the case ultimately, but not all suppliers are equal and not all offerings are the same. So companies need to understand how to go about buying the services and then how to deploy them. For IT Pros, that deployment may be a challenge as there are new issues to consider. Deploying application to hundreds or thousands servers require you to have new automation skills than you might have needed if you just use the GUI to manage one server.
The suppliers of particularly PaaS and IaaS also need to deliver or facilitate training in their offerings. While SQL on Azure may be almost like SQL on your own server, there are differences. Also, deploying and managing larger numbers of servers will require new approaches to the tasks.
For organisations that are considering cloud computing, I’d recommend spending some time to think through just which cloud layers you are considering and the impact those have on your IT staffing. Then you should start to do some training needs analysis. The cloud offers organisations of all sizes some advantages and as Alan poitns out, IT Pros, and hence the training, will certainly adapt to fit the cloud model. But there is still some thinking and planning to be done before leaping off in to cloud-land!
SQLIse – A PowerShell SQL Server Query Tool
I am doing some work at the moment building SQL PowerShell training for an upcoming PowerShell MasterClass. In my searching, I came across a small project being done by Chad Miller, called SQLIse. As Chad describes in his blog, SQLISE is an ISE add-on that provides “a basic IDE for T-SQL that includes the ability to exit, execute, parse and format SQL code from within PowerShell ISE”.
SQLISE is a part of a larger SQL PowerShell project called SQL Extensions for PowerShell or SQLPSX. Having played a bit with both extensions, they are pretty cool and can certainly help IT Pros who have to deal with SQL. Chad has even created a short video to demostrate SQLISE – get this at YouTube: http://www.youtube.com/v/1KcNSHn7oTA&hl=en.
SQLISE has two pre-requisites. First, you need to have the PowerShell Pack installed and you need the SQLPX extensions loaded. You can get PowerShellPack from the MSDN Code Gallery.
One issue I faced was that the SQLIse installation process was not seamless or easy. In order to get this running, I needed two uber-modules (SQLPSX and PowerShellPack) and these come from different places. Second, the installation process requires you to run programs, SQLPSX_Install and PowerShellPack.MSI.
I find this somewhat contrary to the spirit of Modules in PowerShell V2 in that modules should be deployable using only Xcopy. In my case, I did not want either uber-module to be loaded in the personal modules folder, but in the system modules folder. But the installer(s) gave me no option. More importantly, while the SQLPSX installation program seemed to run, but left the module folder empty. A bit of hacking (and running streams.exe across the expanded file set!) enabled me to get the module installed. But sadly the hacking did not work well – and some of the features do not work. More hacking I suspect is needed.
In summary, a great feature let down by the complex installation process.
Wednesday, June 02, 2010
PowerShell Admin Module – A Follow Up
in a recent blog article I wrote about a new Codeplex project called PowerShell Admin Modules, being developed by super-star MVP Richard Siddaway. I noted two small things I’d noticed about the module. Well today, Richard wrote to say he’d fixed Get-Share to accept wildcards and had changed around the parameters of New-Share to match that of the venerable Net Share.
He also mentions the latest version, 0.2, has a bunch of functions for dealing with binary and hex numbers, which include:
- ConvertTo-Binary
- ConvertTo-Decimal
- ConvertTo-Hex
- Get-BinaryAND
- Get-BinaryDifference
- Get-BinaryOR
- Get-BinarySum
- Get-BinaryXOR
- Get-HexDifference
- Get-HexSum
- Test-Binary
- Test-Hex
This is nice work – although one thought would be to merge the functions of PSAM into the PowerShell Community Extensions.
Tuesday, June 01, 2010
The PowerShell Guy Has Returned
Marc, aka The PowerShell Guy is back. In his blog (now back on air), Marc recounts a tale that is all too familiar to many of us: IT problems combined with the demands of a real life. But thanks to those very nice folks over at OrcsWeb, Marc’s site and his many outstanding contributions are back online.
Welcome back to the online world Marc!
Monday, May 31, 2010
Another Reason Why PowerShell Matters
I’ve just been reading an interesting blog article in Peeters Online about fixing a DCOM issue that affects some machines. The issue results in Error Log entries with DCOM Event 10005 – Service can not be started. At least one common cause of this is disabling the Remote Storage Manager. The solution involved some manual registry editing and that is something I really do NOT like doing on production servers.
In PeetersOnline, the author presents a nice PowerShell script to fix the issue. The script opens the remote registry, and does the necessary fixes. The script is parameterised therefore suited to larger organisations but more importantly, seems to handle the key error situations (keys not being found, not able to connect to the remote registry). You could go further, and create a trouble-shooter using the Windows SDK to enable remote admins to do the job even more simply (and perhaps both avoiding doing it where not needed and ensuring it’s done properly where it is).
This script shows how PowerShell can be used both to automate a solution and at the same time ensuring good documentation on what the fix is. The script , but also provides a measure of security from the admin that can’t type well! The reliable repetition of accurate instructions is a key to improving availability. It is things like this that make PowerShell so important.
Sunday, May 30, 2010
Awesome script
This is an awesome script, and one I've put into my profile already!! It might be a good addition to PowerShell Community Extensions.
Sunday, May 23, 2010
PowerShell Admin Module
I’ve been playing a bit with a Codeplex project called PowerShell Admin Modules (PSAM). Developed by Richard Siddaway, PSAM is intended to supply a number of PowerShell modules for use by IT Pros. The first of these modules contains 6 functions that work with shares, as follows:
- Get-Share
- Get-ShareAccessMask
- Get-ShareSecurity
- New-Share
- Remove-Share
Using this module is easy. First download the zip file from Codeplex and expand the contents into your modules folder. Then import the module using Import-Module. It looks like this:
PSH [C:\foo]: import-module PAMSHARES
PSH [C:\foo]: get-command * -module pamshares
CommandType Name Definition
----------- ---- ----------
Function Get-Share ...
Function Get-ShareAccessMask ...
Function Get-ShareSecurity ...
Function New-Share ...
Function Remove-Share ...
Function Set-Share ...PSH [C:\foo]: new-share c:\foo foo2
Share foo2 was created
PSH [C:\foo]: get-share foo2Name Path Description
---- ---- -----------
foo2 c:\fooPSH [C:\foo]: remove-share foo2
The module works well enough although get-share does not seem to support wildcards and the order of the parameters in New-Share is different from that of Net Share (for those of us who even remember Net Share!). I’ve posted a fix to the wildcard issue on CodePlex. For the other issue, one could just change the order of the parameters in New Share. This is the joy of open source proejcts like this – you can fix ‘bugs’ and make your own changes as you see fit.
Friday, May 14, 2010
PowerShell Community Extensions (PSCX) 2.0 Released
A new version of the PowerShell Community Extensions (PSCX), version 2.0, has been released and is available from Codeplex (http://pscx.codeplex.com/releases/45101/download/121340). This free set of PowerShell extensions provides a number of very useful enhancements, particularly new/added cmdlets.
The main purpose behind the 2.0 release was to migrate the code from being a snap-in to being a module. As it’s a module, deployment is really simple – just Xcopy the files into your module folder and use Import-Module to load the module (typically you just put the Import-Module into my $profile). You can of course, put the module somewhere else and specify the full path using the Import-Module cmdlet.
PSCX also includes some NEW cmdlets, including:
- ConvertTo-Metric
- Get-AlternateDataStream
- Test-AlternateDataStream
- Remove-AlternateDataStream
- Unblock-File
- Get-LoremIpsum (lorem)
- Get-TypeName (gtn)
- Get-Uptime
- Get-FileTail (tail)
This package is a great set of very useful extensions. Being module based, deployment is much simplified. I commend this release to all PowerShell users!
Wednesday, May 05, 2010
MSDN Webcast: Powershell for Data Professionals Tomorrow (May 5th)
I just got news of an interesting SQL PowerShell web cast coming up tomorrow. In the webcase, Microsoft SQL Server guru Aaron Nelson is going to look at how you perform everyday database administrator tasks using POwerShell. He’ll cover backing up user databases, scripting table objects, and evaluating disk space usage. The idea is to demonstrate how PowerShell scripts can be used to automating SQL Server activities.
Sign up for the web cast here: MSDN Webcast: geekSpeak: Powershell for Data Professionals (Level 200). I’ll try to post details of the recordings after the event for those that can’t make it.