Posey's Tips & Tricks
How To Track Down Hyper-V VM Errors
Occasionally, Hyper-V's error alerts raise more questions than answers. Here's how to clear up these mystery errors.
When Hyper-V experiences a problem, it usually will display a detailed error message giving you a hint as to what is going on. While I will be the first to admit that these errors can occasionally be misleading, most of the time the error messages are helpful.
Every once in a while, though, Hyper-V will simply show that a virtual machine (VM) is a failed or a critical state without telling you what is going on. I wanted to give you a few pointers for dealing with these mystery errors.
My first suggestion would be to look for anything obvious. For example, nearly every time that I have seen Hyper-V show a VM as being in a critical state, it has been because the host operating system has lost connectivity to the storage where the VM resides.
Another suggestion would be to check the event logs. You can see Hyper-V-specific events in the Event Viewer at Custom Views | Server Roles | Hyper-V. The Event Viewer will usually provide you with detailed information about whatever is going on. Figure 1 shows an example of a Hyper-V-related VM error in the Event Viewer.
It is worth noting, however, that a single event may not paint a complete picture of what is going on. You may need to examine several related events in order to piece the full story together. Depending on what the Event Viewer tells you, the problem may be something that can be fixed using the Hyper-V Manager or some of the tools that are included with Windows Server. In other cases, you may need to delve into PowerShell.
While I realize that there are some people who would really prefer to stick to using GUI-based repair tools, there is some good news. In many cases, you don't have to worry about gathering obscure diagnostic data or running a series of complex and convoluted commands. PowerShell includes cmdlets that greatly simplify the process of repairing failed VMs.
Before I show you how to use PowerShell to fix a Hyper-V VM, there are two important things that I need to tell you. First, make sure that you create a backup of the VM (if possible) before attempting to repair it. Any repair operation, regardless of the tool being used, has at least some potential to cause further damage. As such, it's a good idea to create a backup before attempting any sort of repair.
The other thing is that the technique you will need to use varies depending on whether you are using System Center Virtual Machine Manager (SCVMM). SCVMM has its own collection of PowerShell tools for fixing Hyper-V VMs. These tools are beyond the scope of this column, but if you are using SCVMM, then be sure to check out the Repair-SCVirtualMachine cmdlet.
For environments without SCVMM, the tool that I like to use for diagnostic purposes is Compare-VM. This tool is actually designed for VM migrations, but it can tell you a lot about what is going on with a troubled VM.
Using the Compare-VM cmdlet is really simple. You will need to provide the name of the VM and the name of the destination host. Unfortunately, you can't specify the host that the VM is currently running on, so just pick a Hyper-V host that is configured similarly to the VM's current host (don't worry, the cmdlet won't actually migrate the VM).
When you run the Compare-VM cmdlet, PowerShell will tell you about any problems that stand in the way of a successful migration. Here is the command syntax:
Compare-VM -Name <VM Name> -DestinationHost <Hyper-V Host Name>
It is worth noting that not every error returned by Compare-VM points to a problem with the VM itself. For example, you will receive an error if the destination host is not configured for live migration or if the destination host does not have a Hyper-V virtual switch that has the same name as the host where the VM currently resides.
If the Compare-VM cmdlet does find errors with the VM, then you can use either the GUI or PowerShell to fix the problem. Two of the most commonly used PowerShell cmdlets for fixing VM errors are Set-VM (which fixes virtual disk linkage problems) and Repair-VM (which fixes path-related errors).
About the Author
Brien Posey is a 21-time Microsoft MVP with decades of IT experience. As a freelance writer, Posey has written thousands of articles and contributed to several dozen books on a wide variety of IT topics. Prior to going freelance, Posey was a CIO for a national chain of hospitals and health care facilities. He has also served as a network administrator for some of the country's largest insurance companies and for the Department of Defense at Fort Knox. In addition to his continued work in IT, Posey has spent the last several years actively training as a commercial scientist-astronaut candidate in preparation to fly on a mission to study polar mesospheric clouds from space. You can follow his spaceflight training on his Web site.