$report = @() $metrics = "cpu.usage.average","mem.active.average" $vms = Get-Vm | where {$_.PowerState -eq "PoweredOn"} $start = (get-date).AddDays(-1) Get-Stat -Entity ($vms) -start $start -stat $metrics | ` Group-Object -Property EntityId | %{ $row = ""| Select VmName, Timestamp, vCPU, MinCpu,AvgCpu,MaxCpu,MemAlloc,MinMem,AvgMem,MaxMem $row.VmName = $_.Group[0].Entity.Name $row.Timestamp = ($_.Group | Sort-Object -Property Timestamp)[0].Timestamp $row.vCPU = $_.Group[0].Entity.NumCpu $cpuStat = $_.Group | where {$_.MetricId -eq "cpu.usage.average"} | Measure-Object -Property Value -Minimum -Maximum -Average $row.MinCpu = "{0:f2}" -f ($cpuStat.Minimum) $row.AvgCpu = "{0:f2}" -f ($cpuStat.Average) $row.MaxCpu = "{0:f2}" -f ($cpuStat.Maximum) $row.MemAlloc = $_.Group[0].Entity.MemoryMB $memStat = $_.Group | where {$_.MetricId -eq "mem.active.average"} | Measure-Object -Property Value -Minimum -Maximum -Average $row.MinMem = "{0:f2}" -f ($memStat.Minimum) $row.AvgMem = "{0:f2}" -f ($memStat.Average) $row.MaxMem = "{0:f2}" -f ($memStat.Maximum) $report += $row} $report | Export-Csv "C:\VM-stats.csv" -NoTypeInformation -UseCulture
Change the line "$start = (get-date).AddDays(-1)" accordingly to set how many days of history you want.
Original link :- http://communities.vmware.com/message/1784833#1784833