Recompiling/Reformatting a Collection


using vmware powershell api, i'm trying gather performance metrics several vms in 1 collection.

$stats = get-cluster mycluster | get-vm | get-stat -disk  $stats | sort timestamp | ft -property entity, timestamp, value -auto    entity  timestamp               value  ------  ---------               -----  vm1     12/14/2009 12:20:00 pm    3
vm2 12/14/2009 12:20:00 pm 2 vm2 12/14/2009 12:20:20 pm 0 vm1 12/14/2009 12:20:20 pm 2 vm1 12/14/2009 12:20:40 pm 0 vm2 12/14/2009 12:20:40 pm 7 vm1 12/14/2009 12:21:00 pm 46 vm2 12/14/2009 12:21:00 pm 2 vm1 12/14/2009 12:21:20 pm 7 vm2 12/14/2009 12:21:20 pm 521 vm2 12/14/2009 12:21:40 pm 29 vm1 12/14/2009 12:21:40 pm 51 vm2 12/14/2009 12:22:00 pm 4 vm1 12/14/2009 12:22:00 pm 0

i'd combined timestamp, putting "entity" names (vm names) columns.  end goal, manipulate in excel, create charts, etc.  goal format, mocked up:

timestamp               vm1  vm2  ---------               ---  ---
12/14/2009 12:20:00 pm 3 2 12/14/2009 12:20:20 pm 2 0 12/14/2009 12:20:40 pm 0 7 12/14/2009 12:21:00 pm 46 2 12/14/2009 12:21:20 pm 7 521 12/14/2009 12:21:40 pm 51 29 12/14/2009 12:22:00 pm 0 4

i'm not sure if there's fancy powershell way this.  if not, understand solution may moderately complex custom object creation, for-looping through existing collection , creating new collection?  either way, need hand.

thanks!

does work data?


$new_stats = @()
$stats | group timestamp |% {
$new_stat = "" | select timestamp
$new_stat.timestamp = $_.name
$_.group |% {
add-member -inputobject $new_stat -membertype noteproperty -name $_.entity -value $_.value
}
$new_stats += $new_stat
}

$new_stats | ft -auto

 



Windows Server  >  Windows PowerShell



Comments

Popular posts from this blog

Generating Event ID 91, 44 with CA (In Event Viewer with source as Certsvc)

Group policy default policy cannot be edited because network name not found

Problem when changing update source