Add to Technorati Favorites
Welcome to ThePowerShellGuy.com Sign in | Join | Help

Advanced Windows PowerShell Event 2

Check out the Windows PowerShell solution written by Microsoft Premier Field Engineer Ben Pearce

I did about the same, building a result set of objects first but I did that in one line :

$Skaters = gc c:\scripts\skaters.txt |select  @{n='Name';e={$_.split(',')[0]}},@{n='Score';e={(([int[]]$_.split(',')[1..7] | sort)[1..5] |  measure-object -a ).average}} | sort score -desc

"Gold Medal : {0}, {1}" -f $Skaters[0].name , $Skaters[0].Score
"Silver Medal : {0}, {1}" -f $Skaters[1].name , $Skaters[1].Score
"Bronze Medal : {0}, {1}" -f $Skaters[2].name , $Skaters[2].Score

You see no need for a disconnected recordset here in PowerShell , but if you need one I would recommend using a dataset instead

for some examples see the CSV series

/\/\o\/\/ PowerShelled: more Monad scripts, and a bit more CSV or /\/\o\/\/ PowerShelled: PowerShell out-DataGrid update and more ...

Enjoy,

Greetings /\/\o\/\/

Published Wednesday, February 20, 2008 1:19 PM by MoW

Comments

# re: Advanced Windows PowerShell Event 2

Great minds think alike:-)

Wish I'd thought of using (meaasure-object).average though!

Chris

Wednesday, February 20, 2008 3:23 PM by

# Scripting Games 2008 Event 2 « Get-Powershell

Wednesday, February 20, 2008 10:10 PM by Scripting Games 2008 Event 2 « Get-Powershell

# re: Advanced Windows PowerShell Event 2

Hey /\/\o\/\/,

I really like how you used the range operator to drop the highest and lowest scores.. pretty slick.

By the way, I just wanted to say thanks for all you do for the powersehll community. I love your blog and PowerTab is amazing.

Take care,

Andy

http://www.get-powershell.com

Wednesday, February 20, 2008 10:17 PM by

# re: Advanced Windows PowerShell Event 2

@ Andy

Thanks, and keep up the good work on your blog

Greetings /\/\o\/\/

Thursday, February 21, 2008 5:00 PM by MoW

# Scripting Games: Advanced PowerShell - Event 2 « PowerShell ?? ???????????? ??????????????

Anonymous comments are disabled