vishalramnani
 New Member Posts:68

 |
| 27 Oct 2009 01:11 PM |
|
Hey Guys,
Little help here!
I am trying to format a output of below scriptlet.
$Servers = "Server1","Server2" $ProcessCount = $Servers | foreach { $Count = $(Get-Process -Computername $_ | Where {$_.processname -like "*SampleProcess*"}).count $_ + ": " + $count }
With this i do get the resluts as below..
Server1: 3 Server2: 4
but i do not want it in this way. i want it something like as below...
Server Count ------- ------ Server1 3 Server2 4
I am not sure how to achieve this. Can someone point me to the right direction?
Thanks in advance.
|
|
Vishal Ramnani MCITP - Exchange 2007, MCSE Messaging, MCTS - Win 2008 Config |
|
|
Ayth
 Basic Member Posts:173

 |
| 27 Oct 2009 01:15 PM |
|
Ahh this leads me into my next blog post, if I can ever finish it up. Custom objects is what you want. Try this: $Servers = "Server1","Server2" $colResult = $() foreach ($server in $servers) { $Count = $(Get-Process -Computername $_ | Where {$_.processname -like "*SampleProcess*"}).count $objResult = New-Object System.Object $objResult | Add-Member -memberType NoteProperty -value $Server $objResult | Add-Member -memberType NoteProperty -value $Count $colResult += $objResult } $colResult Let me know if it helps. |
|
| My Blog about Powershell http://poweroftheshell.blogspot.com/
Follow me on twitter @darrinhenshaw |
|
|
Ayth
 Basic Member Posts:173

 |
| 27 Oct 2009 01:18 PM |
|
Actually I mixed that up, try this: $Servers = "Server1","Server2" $colResult = $() foreach ($server in $servers) { $Count = $(Get-Process -Computername $_ | Where {$_.processname -like "*SampleProcess*"}).count $objResult = New-Object System.Object $objResult | Add-Member -memberType NoteProperty -Name Server -value $Server $objResult | Add-Member -memberType NoteProperty -Name Count -value $Count $colResult += $objResult } $colResult |
|
| My Blog about Powershell http://poweroftheshell.blogspot.com/
Follow me on twitter @darrinhenshaw |
|
|
vishalramnani
 New Member Posts:68

 |
| 27 Oct 2009 01:40 PM |
|
Perfect. Thanks Ayth! This one worked with slight modifications. So can you please throw some light on how and where all we can use this Add-Member cmdlet. One i learned just now :) . ---------------- $Servers = "Server1","Server2" $colresult = @() foreach ($server in $Servers) { $agentcount = $(Get-Process -ComputerName $server | where {$_.processname -like "*SampleProcess*"}).count $objResult = New-Object System.Object $objResult | Add-Member -MemberType NoteProperty -value $server -Name Servers $objResult | Add-Member -MemberType NoteProperty -Value $count -Name Count $colresult += $objResult } $colresult ---------------------- Thanks Again. |
|
Vishal Ramnani MCITP - Exchange 2007, MCSE Messaging, MCTS - Win 2008 Config |
|
|
Ayth
 Basic Member Posts:173

 |
| 27 Oct 2009 01:46 PM |
|
Certainly, Add-Member basically does what it says, it allows you to add Members(aka Properties) to objects. To get the desired result you wanted we needed to create a blank object, and then add in the data you wanted. Also, Add-Member doesn't just work on custom objects you created, it can work with the normal Pipeline objects as well. Check out the Powershell Team blog for a little more detail: http://blogs.msdn.com/powershell/archive/2008/09/06/hate-add-member-powershell-s-adaptive-type-system.aspx. Hope that help Vishal. |
|
| My Blog about Powershell http://poweroftheshell.blogspot.com/
Follow me on twitter @darrinhenshaw |
|
|
vishalramnani
 New Member Posts:68

 |
| 27 Oct 2009 01:58 PM |
|
Thanks Ayth. Appreciate your help. |
|
Vishal Ramnani MCITP - Exchange 2007, MCSE Messaging, MCTS - Win 2008 Config |
|
|
Shay
 Veteran Member Posts:1140

 |
|