← script library

Efficient Hyper-V VM Status Reporting Script

Hyper-VJanuary 10, 2025

Monitoring the status of Hyper-V virtual machines is essential for administrators to maintain optimal performance and uptime. In this post, we will share a PowerShell script that retrieves and displays the current state of all Hyper-V virtual machines. This script will help you quickly identify which VMs are running, stopped, or in any other state, enabling effective management of your virtualization environment.

powershell
$VMs = Get-VM
$VMStatusList = @()
foreach ($VM in $VMs) {
    $VMStatusList += [PSCustomObject]@{
        Name   = $VM.Name
        Status = $VM.State
    }
}
$VMStatusList

$VMStatusList | Format-Table -AutoSize
Write-Host "Virtual Machine statuses retrieved successfully."

try {
    $VMs = Get-VM
    if ($null -eq $VMs) {
        throw 'No virtual machines found.'
    }
} catch {
    Write-Host 'ERROR: Unable to retrieve VM status. Details: ' $_.Exception.Message
}

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.