After you install or enable Hyper-V on your Windows 11 or Windows 10 host machine, you can create VMs to run a different operating system (guest OS) for various purposes. In this post, we will show you how to Start & Stop Hyper-V VM using PowerShell.
How to Start & Stop Hyper-V VM using PowerShell
The Hyper-V manager can be used to manually start and stop your virtual machine(s). The Start-VM and Stop-VM cmdlet in PowerShell starts/stops a virtual machine. The cmdlets available in the Hyper-V module can be used to start/stop one or more virtual machines running on Hyper-V hosts.
To start or stop a virtual machine in Hyper-V using PowerShell, run the following corresponding cmdlet. The command starts/stops the virtual machine VM-1 specified by the VMName parameter.
Start-VM -VMName VM-1
Stop-VM -VMName VM-1
By default, the Start-VM cmdlet does not return any output. So, you can use the -PassThru parameter to generate the output and pass it down the pipeline and then use the Get-VM cmdlet to return the status of the VM. The corresponding syntax should look like this:
Start-VM -VMName VM-1 -Passthru | Get-VM
To save the VM state and stop it, you will have to use the -Save parameter as shown below:
Stop-VM -VMName VM-1 -Save
To start or stop more than one virtual machine in Hyper-V using PowerShell, run the following corresponding cmdlet. The command will start/stop all virtual machines whose names start with VM.
Start-VM -VMName VM*
Stop-VM -VMName VM*
Read: How to install Linux Ubuntu on Hyper-V
How to Stop an unresponsive Hyper-V VM
Occasionally, it could be that your Hyper-V virtual machines hang when you are trying to shut them down. When this issue occurs, in Hyper-V Manager, you will see the affected VMs with a status of Shutting down that no longer respond. In addition, you’re unable to force shutdown the VM using the PowerShell Stop-VM -Force command or using the normal controls because when the guest OS stops responding, the Turn Off, Shut Down, and Reset buttons in the Hyper-V Manager are grayed out and return the following error when pressed:
The application encountered an error while attempting to change the state of VM.
Failed to change state.
The operation cannot be performed while the object is in its current state.
In this case, instead of shutting down (which is one way to go, but that’s just an overkill) your server or PC if you are using client Hyper-V, you can force an unresponsive VM to shut down using the methods below:
- PowerShell
- Task Manager or Process Explorer
Let’s see the steps involved for each method.
Read: Hyper-V Virtual Machine stuck in Starting State
1] Stop an unresponsive Hyper-V VM using PowerShell
- Open PowerShell in admin mode.
- Type the command below and hit Enter to get an output of all your VM’s GUID. You will need to know the name of the unresponsive VM.
Get-VM
- Once you have the VM name, run the command below. Substitute the VM_NAME placeholder with the name of the VM you want to stop:
$VmGUID = (Get-VM 'VM_NAME').id
- Next, run the command below to find the process ID of the VM. The command uses the Win32_Process Windows Management Instrumentation (WMI) namespace to find a running CPU process that matches vmwp.exe and the GUID ($VmGUID) of your virtual machine.
$VMWMProc = (Get-WMIObject Win32_Process | ? {$_.Name -match 'VMWP' -and $_.CommandLine -match $VmGUID})
- Once we have the process ID ($VMWMProc), you can run the Stop-Process cmdlet as shown below to kill the process:
Stop-Process ($VMWMProc.ProcessId) –Force
Read: Fix Hyper-V Virtual Machine stuck in Stopping State
2] Stop an unresponsive Hyper-V VM using Task Manager or Process Explorer
All VMs on a Hyper-V host is started using the Virtual Machine Worker Process vmwp.exe process instances that you will have to kill if a VM is stuck. To find a specific process PID, you need to find out the GUID of the virtual machine.
For either of these methods, you can get the VM GUID using the Hyper-V Manager console.
- Open the Hyper-V server settings.
- The Server section contains the directory where the VM configuration files are stored.
- Once you have identified the folder, navigate to the directory in File Explorer.
- At the location, find the folder with the name of your stuck virtual machine.
- Copy the GUID that is specified in the name of the VM configuration file with the
*.vmcx
extension. - Next, open Task Manager and go to the Details tab.
- Now, in the User name column, find and kill the process vmwp.exe that has the GUID of your VM that is stuck.
Similarly, you can the Process Explorer tool to find and stop a stuck virtual machine process on a Hyper-V host by following these steps:
- Run Process Explorer as administrator.
- Next, press the Ctrl-F key combo or click Find Handle or DLL.
- Specify the path to the virtual disk (*.vhdx) of the Hyper-V VM that is stuck in the starting/stopping state.
- Process Explorer will list all processes using the virtual machine VHDX file.
- Now, locate the vmwp.exe virtual machine process.
- Right-click the process and select Kill Process from the menu.
Read: Fix Hyper-V Virtual Machine stuck in Saved State
Another way you can force a VM that isn’t responding to shut down is to stop the Hyper-V service by running the command below in an elevated PowerShell prompt. The Restart-Service command will forcibly shut down all running VMs on your server. Remember that restarting the Hyper-V service (vmms) can take quite a while. So, the operation might take several minutes to stop and then restart again.
Get-Service vmms | Restart-Service
That’s it!
Read next: How to make Hyper-V virtual machine launch automatically at Startup
How do I check my VM status?
To check the status of an individual virtual machine in VMware, do the following:
- In the vSphere Client, navigate to a virtual machine.
- On the Updates tab, click Check Status. The Scan entity task appears in the Recent Tasks pane.
- After the task finishes, status information appears in the VMware Tools and VM Hardware Compatibility panels.
How do I know if my VM is idle?
In Google Cloud, to classify a VM as idle, all of the following conditions must be met:
- CPU utilization is less than 0.03 vCPUs for 97% of VM runtime.
- Received network traffic is less than 2600 bytes per second (B/s) for 95% of VM runtime.
- Sent network traffic is less than 1000 B/s for 95% of VM runtime.