PowerShell: Monitor Hyper-V VM Heartbeat

$hostname = “ServerName”

$service = gwmi -class “Msvm_VirtualSystemManagementService” -namespace “root\virtualization” -ComputerName $hostname

$VM = gwmi -ComputerName $hostname -namespace “root\virtualization” -query “Select * from Msvm_ComputerSystem where Caption=’Virtual Machine'”

Foreach ($_ in $VM)


Write-Host $_.ElementName

$settings = gwmi -ComputerName $hostname -namespace “root\virtualization” -query (“ASSOCIATORS OF {” + $_.__PATH + “} WHERE resultClass = Msvm_VirtualSystemsettingData”)

$HB = $service.GetSummaryInformation($settings.__PATH, 104)

Write-Host $HB.SummaryInformation[0].Heartbeat
#OK (2), #Error (6),No Contact (12), Lost Communication (13), Nothing means Saved or Off



Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s