PowerShell's Script Center problem

PowerShell Team

Fellow Scripters,

We’ve heard that some of you think our PowerShell sample scripts on the TechNet Script Center stink. Do you have any idea how much that hurts? We slave over hot keyboards day in and day out trying to help you ungrateful scoundrels learn more about scripting. And how do you repay us? Nasty emails and smear campaigns, that’s how….just a sec…what’s that?…what do you mean they have a point? Really? Oh. OK.

Ahem. Yes, well then…as I was saying, in my official capacity as someone writing an email message to a fellow named Lee, that I hope he’ll post on a blog for me, I’m here to explain why the PowerShell sample scripts on the Script Center are not at all elegant and basically look like VBScripts translated into PowerShell scripts. For those of you who haven’t experienced the horror first hand (you might want to chase your offspring out of the room at this stage), here’s one of the offending scripts.

$strComputer = "."
$colItems = get-wmiobject -class "Win32_LoadOrderGroup" -namespace "root\CIMV2" `
-computername $strComputer

foreach ($objItem in $colItems) {
      write-host "DriverEnabled: " $objItem.DriverEnabled
      write-host "GroupOrder: " $objItem.GroupOrder
      write-host "Name: " $objItem.Name

If you happen to be into this sort of vulgarity, here’s a link to the entire repository of the beasts: http://www.microsoft.com/technet/scriptcenter/scripts/msh/default.mspx.

So what, exactly, were we thinking? And when are we going to get our act together and post some elegant scripts? Don’t we know that PS:>get-wmiobject Win32_LoadOrderGroup would have accomplished the same thing and demonstrated some of the Power in PowerShell?

Here’s the deal. Our performance is judged by the number of lines of script we write. We needed to figure out a way to keep the line count up and the bonuses rolling in. (you would not believe what it costs to fill up a Ferrari these days!). So, we told management that we wanted to create PowerShell scripts that looked exactly like the typical VBScripts you find on Script Center.

We spun this tale about how we wanted to help ease our beloved Script Center customers into the PowerShell world by showing them how their existing knowledge translates easily to PowerShell. They can still set a strComputer variable to “.” to reference the local machine, they still have a For Each loop, there’s still a statement that let’s them display information on the screen.  Heck, if they look at the two scripts side-by-side, they’ll surely see the parallel statements and thereby be gently introduced to a bit of PowerShell syntax.

On Error Resume Next
strComputer = "."
Set objWMIService = GetObject("winmgmts:" _
    & "{impersonationLevel=impersonate}!\\" & strComputer & "\root\cimv2")
Set colItems = objWMIService.ExecQuery("Select * from Win32_LoadOrderGroup")
For Each objItem in colItems
    Wscript.Echo "Driver Enabled: " & objItem.DriverEnabled
    Wscript.Echo "Group Order: " & objItem.GroupOrder
    Wscript.Echo "Name: " & objItem.Name

Of course we expected to be found out eventually and, apparently, eventually has arrived early this year. So, what are we going to do about it? We’ll we’re not going to take down those existing scripts anytime soon. (we need the line count, remember?). We are, however, working another scam. We’re soliciting elegant PowerShell scripts from internal folks at Microsoft who do have a clue. This is brilliant. We claim that we want to “leverage their expertise” or benefit from their “understanding of real-world customer scenarios” or some other buzz-word-laden suck up sentence and they do our work for us.

Unfortunately, we still have to organize what we get and do the production work required to get the samples posted. We’re a tiny little team and we’re currently working on improving the command line help in PowerShell. Though we’ve tried, we can’t figure out a way to make that work easier or to get someone else to do it for us. So, the new PowerShell script samples are on hold until we’re done.

Now, in case you haven’t picked it up, we’re pretty open to benefiting from the hard work of other people. If you’ve got some elegant PowerShell scripts that you’d like to see on the Script Center, we’d like to help you help us. Just click on the following link, click Submit a Script, agree to donate all of your future earnings to us and fill out the form. No promises, but we’ll do our best to post the submissions (only if they’re elegant of course).



Many thanks (ungrateful scoundrels),

Dean Tsaltas

 Official Spokesman for the Script Center team
….on this one particular, inconsequential issue
….only because the rest of the team didn’t have time and Lee demanded something by the end of the day

[Edit: Fixed some typos]


Discussion is closed.

Feedback usabilla icon