Connect to vCenter (update credentials as needed)

Connect-VIServer -Server “your-vcenter-server”

Define time window for stats (last 30 minutes)

$start = (Get-Date).AddMinutes(-30)
$end = Get-Date

Filter VDI VMs (update identification logic as appropriate)

$vdimvms = Get-VM | Where-Object { $_.Name -like “VDI” -and $_.PowerState -eq “PoweredOn” }

Collect performance data

$results = foreach ($vm in $vdimvms) {
# Gather stats in batch for efficiency
$stats = Get-Stat -Entity $vm -Stat @(
“cpu.ready.summation”,
“mem.latency.average”,
“disk.totalLatency.average”,
“disk.read.average”,
“disk.write.average”
) -Start $start -Finish $end

# Extract and average metrics; protect against missing data
$cpuReady   = $stats | Where-Object {$_.MetricId -eq "cpu.ready.summation"}
$memLatency = $stats | Where-Object {$_.MetricId -eq "mem.latency.average"}
$diskLat    = $stats | Where-Object {$_.MetricId -eq "disk.totalLatency.average"}
$readIOPS   = $stats | Where-Object {$_.MetricId -eq "disk.read.average"}
$writeIOPS  = $stats | Where-Object {$_.MetricId -eq "disk.write.average"}

[PSCustomObject]@{
    VMName        = $vm.Name
    CPUReadyMS    = if ($cpuReady)   { ($cpuReady | Measure-Object -Property Value -Average).Average / 1000 } else { $null }
    MemLatencyMS  = if ($memLatency) { ($memLatency | Measure-Object -Property Value -Average).Average }    else { $null }
    DiskLatencyMS = if ($diskLat)    { ($diskLat | Measure-Object -Property Value -Average).Average }       else { $null }
    ReadIOPS      = if ($readIOPS)   { ($readIOPS | Measure-Object -Property Value -Average).Average }      else { $null }
    WriteIOPS     = if ($writeIOPS)  { ($writeIOPS | Measure-Object -Property Value -Average).Average }     else { $null }
    TotalIOPS     = (
        ((($readIOPS | Measure-Object -Property Value -Sum).Sum) +
         (($writeIOPS | Measure-Object -Property Value -Sum).Sum))
    )
}

}

Display top 10 VMs by disk latency, show table and export to CSV

$timestamp = Get-Date -Format “yyyyMMdd_HHmmss”
$top10 = $results | Sort-Object -Property DiskLatencyMS -Descending | Select-Object -First 10
$top10 | Format-Table -AutoSize
$results | Export-Csv -Path “VDI_VM_Perf_Report_$timestamp.csv” -NoTypeInformation

Notes:

– For environments with large VM counts, consider running data collection in parallel using Start-Job/Runspaces.

– Always verify metric names using Get-Stat -IntervalMins 5 -MaxSamples 1 -Entity (Get-VM | Select-Object -First 1).

– Add additional VM filters (folders/tags) for more targeted results.

Podcast also available on PocketCasts, SoundCloud, Spotify, Google Podcasts, Apple Podcasts, and RSS.

Leave a comment

The Podcast

Join Naomi Ellis as she dives into the extraordinary lives that shaped history. Her warmth and insight turn complex biographies into relatable stories that inspire and educate.

About the podcast