Thursday, September 29, 2016
How to Kill a Hyper-V Virtual Machine in Windows Server 2012
Hyper-V virtual machines can, for lack of a better term, get stuck every now and then. There could be a number of reasons why the VM got stuck, but killing the process that equates to a virtual machine might not be obvious to everyone. It wasn't obvious to me, and it took me bit to figure it out. Here's how to do it in Server 2012.
A stuck VM is a virtual machine that cannot be connected to or managed in any way. The guest OS is unresponsive and Hyper-V Manager no longer displays the "Turn Off", "Shut Down", and "Reset" options. Often, stuck VMs present errors like "failed to change state" and/or "the operation cannot be performed while the object is in its current state." If the VM is still running and you don't want to, or cannot, restart the host server, this is how you can stop the VM.
Open an Explorer window and browse to the location where the offending VM is stored. The default location for virtual machine configuration files is C:\ProgramData\Microsoft\Windows\Hyper-V. If this was changed or if you do not know the location of the VM, open Hyper-V Manager, right click on the host server, and select Hyper-V Settings. Under Server, on the left hand side, is the default location for VMs. Mine are stored in F:\Hyper-V\VMs.
If the VM isn't located in the Virtual Machines folder, you might be able to get an idea where the machine is stored by looking at the settings of the VM itself and noting the locations of the checkpoint and/or paging files.
In the VM folder, each virtual machine should have at least a folder and an XML file named with a long string of numbers and letters known as a Globally Unique Identifier (GUID). Note the name of the file or folder.
Open the Task Manager by right clicking on the Taskbar and choosing Task Manager.
Select the Details tab and sort by the Name column. Find the vmwp.exe (Virtual Machine Worker Process) processes and locate the stuck VM by the GUID in the User name column.
Right click on the process for the stuck virtual machine and select End task.
The stuck virtual machine should be dead... dead. This may or may not solve your problem, but the VM should go down. In some cases, you may not regain control of the VM until you restart the host server, but there are situations where killing the VM does come in handy.