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.

{ 2 trackbacks }