← script library

Retrieve and Report ESXi VM Health Status Using PowerShell

VMware & vSphereJanuary 6, 2025

This script enables you to retrieve the health status of your virtual machines, providing key insights into their performance and operational status. Monitoring VM health is crucial for proactive management and helps ensure your systems are always running optimally.

powershell
# Load VMware PowerCLI module
Import-Module VMware.PowerCLI -ErrorAction Stop

# Define connection parameters
$esxiHost = "<ESXi_Host>"
$username = "<Your_Username>"
$password = "<Your_Password>"
# Securely convert the password
$securePassword = ConvertTo-SecureString $password -AsPlainText -Force
$credentials = New-Object System.Management.Automation.PSCredential ($username, $securePassword)
# Connect to the ESXi host
Connect-VIServer -Server $esxiHost -Credential $credentials -ErrorAction Stop

# Retrieve all VMs and their health status
$vmList = Get-VM
foreach ($vm in $vmList) {
    $status = $vm.ExtensionData.Runtime.PowerState
    $health = $vm.ExtensionData.Summary.QuickStats
    Write-Host "VM Name: $($vm.Name) - Power State: $status - CPU Usage: $($health.OverallCpuUsage) MHz - Memory Usage: $($health.GuestMemoryUsage) MB"
}

# Disconnect from the ESXi host
Disconnect-VIServer -Server $esxiHost -Confirm:$false

Run it across your fleet

This script runs as-is on a single host. Paste it into ServerEngine to schedule it, run it on a whole server group in parallel, and keep the credentials out of the file — see the scripts documentation and the credential store.

Ready when you are.

Try ServerEngine free for 7 days.