← script library

Efficiently Monitor System Health Checks in Hyper-V with PowerShell

Hyper-VDecember 24, 2024

In this post, we will introduce a PowerShell script that enables IT administrators to perform system health checks on Hyper-V virtual machines. Regular health checks are essential for maintaining optimal performance and quickly identifying any issues within your virtual environment. This script checks the status of all virtual machines, reports on their current state, and flags any that are in critical conditions, allowing for proactive management. Here is the PowerShell script for performing system health checks on Hyper-V VMs:

powershell
# Import Hyper-V module
Import-Module Hyper-V
# Get the list of all VMs and their statuses
$vms = Get-VM
# Create an array to hold health check results
$healthReport = @()
foreach ($vm in $vms) {
    $vmState = $vm.State
    $vmStatus = New-Object PSObject -Property @{
        Name   = $vm.Name
        Status = $vmState
    }
    $healthReport += $vmStatus
    # Check for critical states
    if ($vmState -eq 'Critical' -or $vmState -eq 'Stopped') {
        Write-Host "Warning: VM '$($vm.Name)' is in a critical state: $vmState"
    }
}
# Output the health check report
$healthReport | Format-Table -AutoSize
Write-Host "System health check completed for all Hyper-V VMs."

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.