Thank you very much for your input LucD.
I ran the below script and it completed, created the csv file but the file is empty. Anything wrong I am doing here?
(I am new to scripting so kindly ignore any silly questions)
# Connect to vCenter Server
Connect-VIServer VC-NAME
foreach ($vmName in (Get-VMHost -Name MyEsx | Get-VM)) {
# Specify the time range for which you want to get the IOPS data (in minutes)
$startTime = (Get-Date).AddMinutes(-60) # Adjust the time range as needed
$endTime = Get-Date
# Create an array to store the combined report data
$combinedReportData = @()
foreach ($vmName in $vmNames) {
# Get IOPS statistics for the specified VM within the specified time range
$iopsStats = Get-Stat -Entity $vmName -Stat disk.numberRead.summation, disk.numberWrite.summation, virtualdisk.throughput.usage.average -Start $startTime -Finish $endTime
# Check if statistics are available for the current VM
if ($iopsStats -ne $null) {
# Create an array to store the report data for the current VM
$reportData = @()
foreach ($stat in $iopsStats) {
$time = $stat.Timestamp
$readIOPS = $stat.ExtensionData.Value[0].Value
$writeIOPS = $stat.ExtensionData.Value[1].Value
# Create a custom object to store the data
$dataObject = [PSCustomObject]@{
VMName = $vmName
Time = $time
ReadIOPS = $readIOPS
WriteIOPS = $writeIOPS
}
# Add the custom object to the array
$reportData += $dataObject
}
# Add the VM-specific report data to the combined report data
$combinedReportData += $reportData
}
else {
Write-Host "No data available for VM: $vmName within the specified time range."
}
}}
# Export the combined report data to a CSV file
$combinedReportData | Export-Csv -Path "Combined_VM_IOPS_Report.csv" -NoTypeInformation
# Display a message
Write-Host "Combined VM IOPS Report for specified VMs has been generated and saved as Combined_VM_IOPS_Report.csv"