Monthly Archive


Monthly Archives: April 2010

Scripting Games Comments II

With Event 5 now available

we have reached half way.

This event is concerned with retrieving information about the hardware in a machine.  The retrieval is straight forward so this would a good time to go to town on the other aspects that can earn you style points.

To carry on the theme of my last post while there are a lot of good scripts coming through – my definition of  a good script is one that does the required job in  a reasonable time – there are still some pointers that can be given about using PowerShell. I’ve just finished judging the latest submissions and I make about 470 entries at this time. In those there are some things that leapt out as needing comments.

One script had a very interesting way of using the pipeline in that it looked like this

Get-Process `

| select name, Handles `

| format-table


A ` (backtick) is used as a continuation marker and then the pipeline symbol starts the line.  I had to actually test this to see if it would work.  It does.

A simpler syntax is to do this

get-Process |

select name, Handles |



The pipeline symbol will automatically give continuation and save the use of `.  I would really recommend using the second style as a ` can be very difficult to spot when trying to debug a script. The absence of a ` is even more difficult to spot.


The other point that can be made is that we can simplify to

get-Process |

format-table name, Handles

which will give the same result.


Many of the scripts I’ve seen have over complicated the code. Keeping it simple makes it easier to debug.

Scripting Games Comments I

I’m going to produce a few general posts with comments about the scripts I’ve seen.  Some specific points I’ll save until after the Games as they may affect the way you write your entries.

The Events in this years Games are very admin orientated and could well be representative of the sort of tasks you will meet.

I’ve been surprised by how few VBScript entries have come through.  The overwhelming majority of scripts I’ve seen have been PowerShell. Is VBScript disappearing as an admin tool or are VBScripters just not bothering.

In a few cases the rules of the event haven’t been read properly which has detracted from what was a good script – it just wasn’t solving the problem that was asked.

A couple of general points I think are worth repeating:

  1. using aliases is generally not good in production scripts – it also makes the scripts harder to read which makes me grumpy (grumpier?). You don’t want a grump judge  🙂
  2. I would also recommend sticking with the standard verbs when creating function names – it won’t affect the score but its a good habit to get into.  If you don’t know what they are – use get-verb

Scripting Games Event 4 Scenario

The Games continue at a break neck pace with event 4 available as well


In this one we get to play with environmental variables. 


The deadline for Event 1 is looming as that event closes on 3 May.

A couple of PowerShell thoughts

I’ve been looking at a lot of scripts over the last few days and a couple of thoughts occurred while judging.  These have nothing to do with the Scripting Games but are more concerned with PowerShell in general.

Write-Host is used to output to the screen.  That works fine but its not so easy if you want to be able to run the script and output to screen or file.  Consider this

PS> $date = Get-Date
PS> Write-Host "Started at $date"
Started at 04/28/2010 22:54:17

PS>  "Started at $date"
Started at 04/28/2010 22:54:17

We can use write-host to output to screen. We can put the same output by having a line with a string on it – its treated as output.

If we want to write to a file

PS> Write-Host "Started at $date" | out-file test1.txt
Started at 04/28/2010 22:54:17
PS> cat test1.txt

Write-host will always write to the screen.

PS>  "Started at $date" | out-file test1.txt
PS> cat test1.txt
Started at 04/28/2010 22:54:17

Output via a string can be redirected to a file.

Consider what you are trying to achieve. If you want the comments in a file then done use write-host.

The other thought was around how scripts close.  Very often our pipeline will finish with a format-table (or list).  I try to use a select instead.  That means I can add a simple format-table to the end or can write straight out to file – again think about what is being achieved.

Scripting Games Event 3 Scenario

And event 3 is now available

This is all about creating files and adding content.

Think about loops

Scripting Games Event 2 Scenario

Event 2 is now available.

This one I’ll be looking at closely as I wrote the guest commentary for it – look for it when the event is closed

Scripting Games Event 1 Scenario

The Scripting Games have started with Event 1 officially open.

For the beginners section

You need to check a registry key exists, create it if not, & update it with the date & time of the check


For the Advanced section

This is the beginners scenario plus a number of other features including reading file of computer names, running remotely, code reuse – and some others you need to read the scenario for

Good Luck. 

Deadline is 3 may 2010.  After which I’ll post my efforts.

PowerShell Admin Modules

I have created the first download for the PowerShell Admin Modules. This will be a set of of modules including code previously published on my blogs at:


The first release comprises a module for working with shares and can be found at:


It has the following functions:

  • Get-Share
  • Get-ShareAccessMask
  • Get-ShareSecurity
  • New-Share
  • Remove-Share
  • Set-Share

There have been a series of posts on my IT Knowledge Exchange blog (see above) about the functions.  Select Shares from the

Browse This Blog’s Tags box

More to follow soon. Enjoy

Technorati Tags: PowerShell,Modules,Shares,PSAM

Office 2010

Office 2010 recently went RTM and is now available fro download from MSDN/TechNet.  Downloaded and installed without a problem.  I removed the beta versions – having remembered to export my auto correct entries.  Install went smooth and import the auto correct entries.

Tested each of the applications and everything seems to work.

After using the beta for so long I’d forgotten it was a beta – everything worked perfectly for me.

I expect the RTM version to be the same.  You’ll only hear more about Office if I find a problem or I’m using PowerShell against it.

One quick test

$xl = New-Object -ComObject "Excel.Application"
$xlbooks = $xl.workbooks.Add()
$xl.Visible = $true

Works for creating an Excel spreadsheet – at least it does under en-GB culture.  If it doesn’t work elsewhere I’d be interested in hearing about it.


Technorati Tags: Office 2010

Binging PowerShell

I posted recently about PowerShell help information being available in the Visual Search galleries on Bing -

The URLs are available to find this directly.  For the time being its only available on the US version of Bing but if you are using PowerShell v2 you can do this

if ($psculture -ne "en-US") {Start-Process}
else {Start-Process}


The culture is checked to see if you are in the US and if so you are pointed straight to Bing. otherwise you are directed to the US version of Bing. As the PowerShell reference is rolled out on other versions of Bing you can always alter the comparison to test your culture – change it to $psuiculture which will probably return en-US.

Technorati Tags: PowerShell,help files,Bing