Lucd - I too have a question on how to aggregate the results for a cluster. Here is the script I am running, but the numbers that are received when totaled up don't equal the same value on the performance chart for Max CPU Usage in MHZ.
$allvms = @()
$allhosts = @()
$hosts = Get-VMHost
$vms = Get-Vm
foreach($vmHost in $hosts){
$hoststat = "" | Select HostName, Cluster, CPUMax, CPUAvg, CPUMin
$hoststat.HostName = $vmHost.name
$hoststat.Cluster = $cluster
$statcpu = Get-Stat -Entity ($vmHost)-start (get-date).AddDays(-7) -Finish (Get-Date)-MaxSamples 10000 -stat cpu.usagemhz.average
$cpu = $statcpu | Measure-Object -Property value -Average -Maximum -Minimum
$cluster = (Get-Cluster -VMHost $vmHost).Name
$hoststat.CPUMax = [int]$cpu.Maximum
$hoststat.CPUAvg = [int]$cpu.Average
$hoststat.CPUMin = [int]$cpu.Minimum
$hoststat.Cluster = $cluster
$allhosts += $hoststat
}
$allhosts | Select HostName, Cluster, CPUMax, CPUAvg, CPUMin | Export-Csv "c:\Hosts.txt" -Delimiter ";" -NoTypeInformation
This script produces the following output:
"HostName";"Cluster";"CPUMax";"CPUAvg";"CPUMin"
"hostclust1-1.vm.local";"Cluster1";"46376";"6292";"4684"
"hostclust1-2.vm.local";"Cluster1";"49635";"7401";"5792"
"hostclust1-3.vm.local";"Cluster1";"51518";"6223";"4475"
"hostclust1-4.vm.local";"Cluster1";"55879";"6756";"4742"
"hostclust1-5.vm.local";"Cluster1";"53818";"6757";"4836"
"hostclust1-6.vm.local";"Cluster1";"57784";"5578";"3771"
"hostclust1-7.vm.local";"Cluster1";"54190";"5567";"3496"
"hostclust1-8.vm.local";"Cluster1";"50340";"6571";"4392"
"hostclust1-9.vm.local";"Cluster1";"58277";"7059";"3895"
"hostclust1-10.vm.local";"Cluster1";"60654";"5089";"3275"
"hostclust1-11.vm.local";"Cluster1";"49669";"6353";"4094"
"hostclust1-12.vm.local";"Cluster1";"42946";"5789";"3769"
"hostclust1-13.vm.local";"Cluster1";"50591";"7800";"5501"
"hostclust1-14.vm.local";"Cluster1";"49325";"5844";"3986"
"hostclust1-15.vm.local";"Cluster1";"60623";"5666";"2485"
"hostclust1-16.vm.local";"Cluster1";"51526";"4869";"3002"
"hostclust2-1.vm.local";"Cluster2";"17465";"2881";"2197"
"hostclust2-2.vm.local";"Cluster2";"28154";"6198";"3962"
"hostclust2-3.vm.local";"Cluster2";"35138";"5819";"4300"
"hostclust2-4.vm.local";"Cluster2";"19091";"2742";"1762"
"hostclust2-5.vm.local";"Cluster2";"24800";"3293";"2481"
"hostclust2-6.vm.local";"Cluster2";"24044";"3093";"2218"
"hostclust2-7.vm.local";"Cluster2";"22093";"2518";"1949"
"hostclust2-8.vm.local";"Cluster2";"20515";"2296";"1850"
"hostclust2-9.vm.local";"Cluster2";"38523";"6052";"4516"
"hostclust2-10.vm.local";"Cluster2";"18869";"3215";"2401"
"hostclust2-11.vm.local";"Cluster2";"20174";"3639";"3010"
"hostclust2-12.vm.local";"Cluster2";"18870";"2411";"1655"
What would I change to give me an output of the following:
"Cluster";"CPUMax";"CPUAvg";"CPUMin"
"Cluster1";"this is max total for all hosts in cluster";"this is average for all hosts in cluster";"This is the min for all hosts in cluster"
"Cluster2";"this is max total for all hosts in cluster";"this is average for all hosts in cluster";"This is the min for all hosts in cluster"
Thanks in advance
Greybear1223