Learn What IT Pros Need to Know About Windows 11 - August 24th at 1 PM ET! Learn What IT Pros Need to Know About Windows 11 - August 24th at 1 PM ET!
Hyper-V

How to Stop an Unresponsive Hyper-V Virtual Machine

It doesn’t happen that often but sometimes Hyper-V virtual machines (VM) hang when you are trying to shut them down. And you end up with a VM in Hyper-V Manager with a status of ‘Shutting down’ that no longer responds, and it can’t be forced to shut down using the normal controls. Even the PowerShell Stop-VM -Force command doesn’t help.

In this situation, you need to be more creative about shutting down the VM. One way is to shut down your server (or PC if you are using client Hyper-V). But that’s something of a sledgehammer solution. The most important thing you need if you want to force an unresponsive VM to shut down, is the VM’s GUID. Using the GUID, you can find the VM’s CPU process ID and kill it.

Force a Hyper-V virtual machine to shut down by killing its process

Using the method below is only recommended if the VM is not responding to a shutdown command from Hyper-V Manager or using the PowerShell Stop-VM -Force command. The following commands must be run in Windows PowerShell as a local administrator. The method below requires Windows PowerShell. It doesn’t work in PowerShell 6 or later versions.

In an elevated Windows PowerShell prompt, start by using Get-VM to find the VM’s GUID. You will need to know the name of the unresponsive VM to do this. If you need to confirm the VM’s name, just run Get-VM to see a list of all the VMs running on the device.

Sponsored Content

Read the Best Personal and Business Tech without Ads

Staying updated on what is happening in the technology sector is important to your career and your personal life but ads can make reading news, distracting. With Thurrott Premium, you can enjoy the best coverage in tech without the annoying ads.

Get-VM

Once you have the VM name, run the command below, replacing ‘Windows 11’ with the name of the VM you want to stop:

$VmGUID = (Get-VM 'Windows 11').id

The next step is to use Get-WMIObject to find the process ID of the VM. Here we use the Win32_Process Windows Management Instrumentation (WMI) namespace to find a running CPU process that matches vmwp.exe and the GUID ($VmGUID) of our virtual machine.

$VMWMProc = (Get-WMIObject Win32_Process | ? {$_.Name -match 'VMWP' -and $_.CommandLine -match $VmGUID})

Once we have the process ID ($VMWMProc), we can use the Stop-Process cmdlet to kill it:

Stop-Process ($VMWMProc.ProcessId) –Force
Unresponsive Hyper-V
How to Stop an Unresponsive Hyper-V Virtual Machine (Image Credit: Russell Smith)

Force all VMs to shut down

The other way you can force a VM that isn’t responding to shut down is to stop the Hyper-V service. But this method will forcibly shut down all running VMs on your server. Just as with the previous method, you need to run the following command in an elevated PowerShell window, i.e. one that has local administrator privileges.

Get-Service vmms | Restart-Service

Restarting the Hyper-V service (vmms) can take quite a while. So, don’t worry if it takes several minutes to stop and then restart it again.

Related Topics:

BECOME A PETRI MEMBER:

Don't have a login but want to join the conversation? Sign up for a Petri Account

Register
Comments (0)

Leave a Reply

IT consultant, Contributing Editor @PetriFeed, and trainer @Pluralsight. All about Microsoft, Office 365, Azure, and Windows Server.

Register for Advanced Microsoft 365 Day!

GET-IT: Advanced Microsoft 365 1-Day Virtual Conference - Live August 24th!

Join us on Tuesday, August 24th and hear from Microsoft MVPs and industry experts about how to take advantage of Microsoft 365 at a technical level and dive deep into the features and functionality that will make your environment more secure and compliant.

RSVP Now

Sponsored By