# This VMware PowerCLI Script will list all VM's in your vCenter and dump to a file the latest disk I/O Usage status
# This script has been tested on VMware Center 8.X and works for me at least; your mileage may vary...
# The file will be located in the same directory as the script results.csv
# Before using the script you will need to provide your credentials below under vCenter Connection Details
#
# Import VMware PowerCLI module
Import-Module VMware.PowerCLI
# Ignore SSL certificate validation
Set-PowerCLIConfiguration -InvalidCertificateAction Ignore -Confirm:$false
# vCenter Connection Details
#$vcenterServer = "vcenter name or IP"
#$username = "username@domain.local"
#$password = "Password"
# Connect to vCenter
Connect-VIServer -Server $vcenterServer -User $username -Password $password
# List of specific metrics to retrieve
$metrics = @(
"virtualdisk.mediumseeks.latest",
"virtualdisk.smallseeks.latest",
"virtualdisk.writeiosize.latest",
"virtualdisk.writelatencyus.latest",
"virtualdisk.readoio.latest",
"virtualdisk.totalwritelatency.average",
"virtualdisk.totalreadlatency.average",
"virtualdisk.numberwriteaveraged.average",
"virtualdisk.numberreadaveraged.average",
"virtualdisk.write.average",
"virtualdisk.read.average",
"virtualdisk.readloadmetric.latest",
"virtualdisk.readlatencyus.latest",
"virtualdisk.writeloadmetric.latest",
"virtualdisk.writeoio.latest",
"virtualdisk.readiosize.latest",
"virtualdisk.largeseeks.latest"
)
# Function to get a specific virtual disk statistic for a VM
function Get-SpecificVirtualDiskStat {
param (
[Parameter(Mandatory=$true)]
[VMware.VimAutomation.ViCore.Types.V1.Inventory.VirtualMachine]
$VM,
[Parameter(Mandatory=$true)]
[string]
$MetricName
)
$stat = Get-Stat -Realtime -MaxSamples 1 -Entity $VM -Stat $MetricName -ErrorAction SilentlyContinue
return $stat
}
# Create an array to hold the results
$results = @()
# Iterate through all VMs
Get-VM | ForEach-Object {
$vm = $_
$vmName = $vm.Name
# Temporary object to hold all metrics for a VM
$vmMetrics = New-Object PSObject -Property @{ VMName = $vmName }
# Iterate through each metric for the VM
foreach ($metric in $metrics) {
$stat = Get-SpecificVirtualDiskStat -VM $vm -MetricName $metric
if ($stat -and $stat -ne "System.Object[]") {
# Check if the response is an array, and set to null if it is
$value = if ($stat.Value -is [Array]) { $null } else { $stat.Value }
$vmMetrics | Add-Member -MemberType NoteProperty -Name $metric -Value $value
} else {
$vmMetrics | Add-Member -MemberType NoteProperty -Name $metric -Value $null
}
}
$results += $vmMetrics
}
# Export the results to a CSV file
$results | Export-Csv -Path "results.csv" -NoTypeInformation
# Disconnect from vCenter
Disconnect-VIServer -Server $vcenterServer -Confirm:$false