Hyper-V, Hyper-V v2, Resources, Scripting, Server 2008 R2, Virtualization, Windows
comments 2

Hyper-V: Detecting VM heartbeat loss

Recently, someone requested for a script to detect a VM’s heart beat loss and then perform a hard reset. With the experience from HVS2008 UI at hand, it was quite a simple task. I have uploaded the attached script.

All you need to do is, on the Hyper-v host, download the attached zip and extract the contents to a folder of your choice. All you need to do, now, is just run the script by double-clicking on it or running at a command prompt by using cscript.

C:\Scripts>cscript VMHeartBeat.vbs

That is it. You are all set to detect the VM heart beat loss and then perform a hard reset. In addition to performing a hard reset, this script will write this information to a log file at the same location as the script. The log file will contain a few entries like

Virtual Machine: Exchange_SP1 has been successfully recovered from a hearbeat failure

To test if the script is working or not, you can download NotMyFault.exe and then copy it to the VM. Now, just run VMHearBeat.vbs on Hyper-V host and open up notmyfault.exe inside the VM, select a bug and  click “Do Bug”. Based on what kind of a bug you select, VM may blue screen. At this point in time, VMHearBeat.vbs would have detected the heart beat loss and performed a hard reset of the virtual machine. You may check the log file, as mentioned earlier, to see if the hard reset was successful or not.

Let me know what you think about this script. I am planning to improve the script to add Windows event log messages when a hard reset occurs.

[Code]

[download id=”2″ format=”4″]

[/Code]

Filed under: Hyper-V, Hyper-V v2, Resources, Scripting, Server 2008 R2, Virtualization, Windows

by

Ravikanth is a principal engineer and the lead architect for Microsoft and VMware virtualized and hybrid cloud solutions within the Infrastructure Solutions Group at Dell EMC. He is a multi-year recipient of Microsoft Most Valuable Professional (MVP) award in Windows PowerShell (CDM) and Microsoft Azure. Ravikanth is the author of Windows PowerShell Desired State Configuration Revealed (Apress) and leads Bangalore PowerShell and Bangalore IT Pro user groups. He can be seen speaking regularly at local user group events and conferences in India and abroad.