I ran it again and it worked. Thanks!!
Do you know of any way to add the Max read and Max write values? As well as the Average Read and Average Write? Giving IOPSAvg and IOPSMax?
I tried this but I got numbers far higher than I expected.
$metrics = "disk.numberwrite.summation","disk.numberread.summation"
$finish = Get-Date -Hour 0 -Minute 0 -Second 0
$start = $finish.AddDays(-1)
$report = @()
$vms = Get-VM | where {$_.PowerState -eq "PoweredOn"}
$stats = Get-Stat -Stat $metrics -Entity $vms -Start $start -Finish $finish
$interval = $stats[0].IntervalSecs
$lunTab = @{}
foreach($ds in (Get-Datastore -VM $vms | where {$_.Type -eq "VMFS"})){
$ds.ExtensionData.Info.Vmfs.Extent | %{
$lunTab[$_.DiskName] = $ds.Name
}
}
$report = $stats | Group-Object -Property {$_.Entity.Name},Instance | %{
$readStat = $_.Group |
where{$_.MetricId -eq "disk.numberread.summation"} |
Measure-Object -Property Value -Average -Maximum
$writeStat = $_.Group |
where{$_.MetricId -eq "disk.numberwrite.summation"} |
Measure-Object -Property Value -Average -Maximum
New-Object PSObject -Property @{
VM = $_.Values[0]
Start = $start
Finish = $finish
Disk = $_.Values[1]
IOPSMax = [math]::Round($writeStat.Maximum+$readStat.Maximum//$interval,0)
IOPSAvg = [math]::Round($writeStat.Average+$readStat.Average/$interval,0)
Datastore = $lunTab[$_.Values[1]]
}
}
Send-MailMessage -Subject "IOPS Report" -From asdf@asdf.com `
-To me@me.com -SmtpServer mail.mailserver.com `
-BodyAsHtml -Body ($report | Select VM,Start,Finish,Datastore,IOPSAvg,
IOPSMax | Sort-Object IOPSAvg -descending | ConvertTo-Html | Out-String)