Managing VMs stuck in the ‘Starting’ or ‘Stopping’ state in Hyper-V

Every now and then, Hyper-V virtual machines for various reasons decide that they don’t want to start or stop correctly and get stuck in the ‘Starting’ or ‘Stopping’ state.

svm00

This is a bit of a pain and the last thing we want to do as an administrator is have to migrate all the other virtual machines to reboot the Hyper-V host. Especially if the host is managing large numbers of running machines or is not part of a cluster and migrating the other running machines may take sometime or impact their running in any way.

One way its possible to kill off that stuck virtual machine is to open Task Manger and end the task responsible for that machine. Unfortunately its not quite that simple because the Virtual Machine Worker Process which is responsible for running the virtual machine appears numerous times, once for each running guest machine!

So how do we differentiate between them?

1. First we need to open Task Manger and view the process tab
2. Then right click on the column titles and add in the Command Line column

svm01

3. Expand the Command Line column to view the full command, including the machine GUIDs at the end of each line

svm02

4. Browse to the location where the virtual machines are stored and open the folder of the virtual machine which is currently hung. From here we can find the machine configuration file and make note of the GUID for that machine

svm03

5. Now we know which GUID relates to the virtual machine that we are looking to stop. Jump back to Task Manger, right click on the correct process and End Process

svm05

NOTE: this process should only be used as a last resort as it could cause corruption of the virtual machine!

Another way to locate the GUID of the machines running on the server is to use PowerShell to output the machine names and associated GUID

Get-VM | Select Name, Id

svm04

There are various way to work out which virtual machine is which Virtual Machine Worker Process in Task Manager.

In Task Manger, it is also possible to add the Process ID column as well as the Command Line and then work out which process is attached to which VM.

svm06

I don’t confess to be the best at putting together PowerShell commands but the line below pulls a list of virtual machine names and GUIDs then compares that to a list of GUIDs in the Command Line of the processes running and returns virtual machine names with the associated Process ID.

Get-WmiObject Win32_Process -Filter "Name like '%vmwp%'" | %{$vm=get-vm -id $_.CommandLine.split(" ")[1];"$($_.processID)`t$($vm.name)"}

svm09

Once we have the list of machine names and Process IDs we can then return to Task Manger and end the correct process.

Another alternative to Task Manger would be to Sysinternals Process Explorer which can be downloaded and used instead.

 

Reader Comments

  1. Worked like a charm, very helpful. My vm was stuck at starting 1%. Ended the appropriate vm worker process. The cluster automatically moved the vm to another cluster member and it started right up. Thanks!

  2. Thank you.. for detail explenation with screen captures. I manage to quickly solve an issue with hung vm using ps script.

Leave a Reply to Raj Cancel reply

Your email address will not be published. Required fields are marked *