Wednesday 18 July 2012

LttP: Powershell Games 2012 - Beginner Event 2

Before I go reading the expert comentary I'll post my "entry"; then update if I'm wrong.

Beginner Event 2:

Get-Service -ComputerName localhost | Where-Object {$_.Status -eq "Running"}
UPDATE:

It looks like I fell into a well placed trap, that I'm sure others did during the games as well.

After reading the expert commentary I've learned my lesson and will be using Get-Member as well as Get-Help in future!

My reviewed entry would be:
Get-Service -ComputerName localhost | Where-Object {$_.CanStop}
The output looks similar, but there is a big difference between something that is Running, and something that "can stop" as the requirements state.

Oh well, I got this one wrong but at least I learned somethings!

1 comment:

Mike F Robbins said...

Consider using $Env:ComputerName instead of localhost. Aliases and positional parameters are acceptable in one liners.

Here's what I submitted for this one:
https://2012sg.poshcode.org/2569

And here's a blog I wrote about it:
http://mikefrobbins.com/2012/04/11/get-method-my-madness-2012-powershell-scripting-games-beginner-event-2/

Mike F Robbins
http://mikefrobbins.com