Ok, I think I see what you want.
Try this version
$midnight=Get-Date-Hour0-Minute0-Second0
$metrics_rp="cpu.usagemhz.average","cpu.usagemhz.maximum"
$rp=Get-Cluster-NameITSDEV|Get-ResourcePool
Get-Stat-Entity$rp-Stat$metrics_rp-Start$midnight.adddays(-1).addminutes(-1) -Finish$midnight.addminutes(-1) |
Group-Object-Property {$_.EntityId} |%{
$cluster=&{
$parent=$_.Group[0].Entity.Parent
while ($parent-and$parent.ExtensionData-isnot [VMware.Vim.ClusterComputeResource]){
$parent=$parent.Parent
}
$parent
}
$hourAvg=@()
$hourMax=@()
$_.Group|Group-Object-Property {$_.Timestamp.Hour} |%{
$hourAvg+=$_.Group|Where {$_.MetricId-eq"cpu.usagemhz.average"} |
Measure-Object-PropertyValue-Average|Select-ExpandPropertyAverage
$hourMax=$_.Group|Where {$_.MetricId-eq"cpu.usagemhz.maximum"} |
Measure-Object-PropertyValue-Maximum|Select-ExpandPropertyMaximum
}
$report=@()
$row=""|Select"Interval Start","Resource Pool",Cluster,"CPU MHz Avg","CPU MHz Max"
$row."Interval Start"=$_.Group|Sort-Object-PropertyTimestamp|
Select-First1|Select-ExpandPropertyTimestamp
$row.Cluster=$cluster.Name
$row."Resource Pool"=$_.Group[0].Entity.Name
$row."CPU MHz Avg"=$hourAvg|Measure-Object-Average|
Select-ExpandPropertyAverage
$row."CPU MHz Max"=$hourMax| Measure-Object-Maximum|
Select-ExpandPropertyMaximum
$report+=$row
$report|Export-CsvC:\$($cluster.Name)-$($_.Group[0].Entity.Name)_stats.csv
}
Note that there will be 1 CSV file per resourcepool. Is that what you want ?