header image

Scripting Games Comments II

Posted by: | April 30, 2010 | No Comment |

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.

under: PowerShellV2, Scripting Games