← script library
Efficient System Health Checks for VMware with PowerShell
VMware & vSphereJanuary 4, 2025
Maintaining the health of your VMware environment is essential for optimal performance and reliability. Regular health checks can help identify issues before they impact your operations. This PowerShell script automates the process of checking the state of your VMware virtual machines, monitoring their CPU, memory utilization, and overall status. Follow these steps to implement a system health check for your VMware infrastructure.
powershell
# Install the VMware PowerCLI module if its not already installed
Install-Module -Name VMware.PowerCLI -Force
# Connect to the vCenter server
$vcServer = "your_vcenter_server" # Replace with your vCenter server address
$vcUser = "your_username" # Replace with your username
$vcPassword = "your_password" # Replace with your password
$securePassword = ConvertTo-SecureString $vcPassword -AsPlainText -Force
$cred = New-Object System.Management.Automation.PSCredential $vcUser, $securePassword
Connect-VIServer -Server $vcServer -Credential $cred
# Retrieve information on all virtual machines
$vms = Get-VM | Select-Object Name, PowerState, @{Name="CPU Usage (%)"; Expression={[math]::round($_.CpuUsage / $_.NumCpu / 10, 2)}}, @{Name="Memory Usage (MB)"; Expression={[math]::round($_.MemoryUsage / 1MB, 2)}}
# Display the VM health check results
$vms | Format-Table -AutoSize
# Export the results to a CSV file
$vms | Export-Csv -Path "C:\VM_Health_Check_Results.csv" -NoTypeInformationRun 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.