In this post, we are sharing a useful PowerShell script designed to help you monitor the status of your VMware ESXi hosts. This script retrieves vital information about each hosts power state and overall health, making sure you stay updated on system performance. This is especially useful for administrators managing multiple VMware environments. It is designed to streamline server management tasks for IT professionals.
powershell
# Load VMware PowerCLI module
Import-Module VMware.PowerCLI -ErrorAction Stop
# Define variables
$esxiHost = "<ESXi_Host>"
$username = "<Your_Username>"
$password = "<Your_Password>"
# Create a secure password
$securePassword = ConvertTo-SecureString $password -AsPlainText -Force
# Create a credentials object
$credentials = New-Object System.Management.Automation.PSCredential ($username, $securePassword)
# Connect to the ESXi host
Connect-VIServer -Server $esxiHost -Credential $credentials -ErrorAction Stop
# Get a list of all ESXi hosts and display their power state
$hosts = Get-VMHost
foreach ($host in $hosts) {
Write-Host "Host: $($host.Name) - State: $($host.State) - CPU Usage: $($host.CpuUsageMhz) MHz - Memory Usage: $($host.MemoryUsageMB) MB"
}
# Disconnect from the ESXi host
Disconnect-VIServer -Server $esxiHost -Confirm:$falseRun 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.
More in VMware & vSphere
Ready when you are.
Try ServerEngine free for 7 days.