Hyper-V is a Microsoft proprietary Hypervisor tool that allows you to create and run virtual machines. By default, when you shut down your VM, it saves the machine’s state; however, this can be changed. In this post, we will see how to change the automatic stop action of the Hyper-V Virtual Machine.
Change Automatic Stop Action of Hyper-V Virtual Machine
The default setting for Hyper-V automatically saves the state of virtual machines when the host is shut down or restarted. This means that if a virtual machine was running before the shutdown or restart, Hyper-V will start it automatically on the next startup. This setting can be adjusted for each virtual machine.
There are three options for managing the automatic stop action of a virtual machine:
- Save the virtual machine state: This option reserves disk space equal to the amount of memory used by the virtual machine when it is running, allowing the memory to be written to disk when the physical computer shuts down or restarts. The virtual machine will automatically start on the next startup and continue running as it was.
- Turn off the virtual machine: This option abruptly shuts down the virtual machine without saving any state information. The guest operating system will start up as if the virtual machine lost power.
- Shut down the guest operating system: With this option, the guest operating system of the virtual machine will be gracefully shut down before the host is shut down or restarted. No state is saved, but the downside is that the guest operating system and its services will take time to start up when the host restarts. If this option is selected, it’s important to consider delaying and ordering the startup of virtual machines.
To change the automatic stop action of the Hyper-V Virtual Machine, you need to be an administrator. If you are an administrator, use one of the following methods.
Change Automatic Stop Action using Hyper-V Manager
Let us start with the easiest method: we are going to alter the Hyper-V Manager’s automatic stop action. You can follow the steps mentioned below to do the same.
- Open the Hyper-V Manager by searching it out of the Start Menu.
- Then, right-click on the virtual machine you want to configure and click on Settings.
- You can change the state to Save the virtual machine state, Turn off the virtual machine, or Shut down the guest operating system by checking the box associated with it and then clicking on OK.
Once done, you can start your virtual machine and when you shut it down, it will stop in the assigned state.
Read: Hyper-V Virtual Machine stuck in Starting State
Change Automatic Stop Action using PowerShell
You can change the stop action using Windows PowerShell. To do so, open PowerShell as an administrator.
First of all, we need to find the name of your current virtual machine, to do so, you can run Get-VM.
Now, to change the state to “Save the virtual machine state”, run the following command.
Set-VM -Name "VMName" -AutomaticStopAction Save
To change the state to “Turn off the virtual machine”, use the following command.
Set-VM -Name "VMName" -AutomaticStopAction TurnOff
To switch to the “Shut down the guest operating system” state, run the below command.
Set-VM -Name "VMName" -AutomaticStopAction ShutDown
Make sure to replace VMName with the actual name of your virtual machine.
In order to check the saved state of the virtual machine, you can run the following command.
Get-VM -VMName * | Select-Object VMName, AutomaticStartAction, AutomaticStartDelay, AutomaticStopAction
This will tell you your current Automatic Stop Action and the Start Action, if you have set any.
Read: How to Start & Stop Hyper-V VM using PowerShell?
How do I stop Hyper-V from automatically starting?
To stop Hyper-V from automatically starting, you need to change the Automatic Start State. To do so, right-click on your virtual machine in Hyper-V Manager, go to Automatic Start State, and then select Nothing or Automatically start delay and set a Startup delay time.
Read: Fix Hyper-V Virtual Machine stuck in Stopping State
What is the automatic start and stop action for a virtual machine?
Automatic Start Action controls whether a VM starts when the host starts. It has three options: do nothing, start if it was running, and delay start. Similarly, Automatic Stop Action controls what happens when the host shuts down. It has three options: Save state, Turn off, and Shut down the guest operating system.