Wednesday, 18 July 2012

Late to the Party - Powershell Games 2012 - Beginner Event 1

Well,  I had some downtime at work today which led me to spend some time brushing up on my scripting skills.

On my adventures across the web trying to find some "Powershell Challenges" I found the "Powershell Games 2012".  Like the title says, I'm late to this party; they kicked off and finshed back in April. 

Still, late is better than never, so I'm going to tackle the challenges and document my progress here :)

Beginner Event 1:

Here's my "entry":

Get-Process | Sort-Object -Property "WS" -Descending | select -First 10
The output looks like this:

3 comments:

Mike F Robbins said...
This comment has been removed by the author.
Mike F Robbins said...

Thought I would leave you some comments based on my experience in the scripting games this year.

Even though your script is similar to the expert commentary, it doesn't meet the requirement of "your boss has directed you to ascertain the top ten processes that are consuming memory resources on each computer." If your script is run against more than one computer, it will return the top 10 for all (not each) computers. You would have to do something like this in order to achieve that result:

Invoke-Command -ComputerName $Env:ComputerName {Get-Process | sort WS -Descending | select -First 10}

Or:

$Env:ComputerName | ForEach {Get-Process -ComputerName $_ | sort WS -Descending | select -First 10}

The scenario states that remoting is enabled so I prefer the first one over the second.

Here's the script I submitted for this event:
https://2012sg.poshcode.org/2162

And a couple of blogs I wrote about this event:

http://mikefrobbins.com/2012/04/10/my-approach-to-the-2012-powershell-scripting-games-beginner-event-1/

http://mikefrobbins.com/2012/04/23/interesting-how-people-are-claiming-to-have-same-beginner-1-solution-as-the-expert-solution-but-still-did-not-get-5-stars/

Mike F Robbins
http://mikefrobbins.com

Owen said...

Awesome!

Thanks for your input. I really put these up to act as my own personal archive. I really didn't expect anyone to read them, let alone comment on them!

I definately want to take part in next years games.