Windows OS Hub
  • Windows
    • Windows 11
    • Windows Server 2022
    • Windows 10
    • Windows Server 2019
    • Windows Server 2016
  • Microsoft
    • Active Directory (AD DS)
    • Group Policies (GPOs)
    • Exchange Server
    • Azure and Microsoft 365
    • Microsoft Office
  • Virtualization
    • VMware
    • Hyper-V
  • PowerShell
  • Linux
  • Home
  • About

Windows OS Hub

  • Windows
    • Windows 11
    • Windows Server 2022
    • Windows 10
    • Windows Server 2019
    • Windows Server 2016
  • Microsoft
    • Active Directory (AD DS)
    • Group Policies (GPOs)
    • Exchange Server
    • Azure and Microsoft 365
    • Microsoft Office
  • Virtualization
    • VMware
    • Hyper-V
  • PowerShell
  • Linux

 Windows OS Hub / Virtualization / Hyper-V / Hyper-V: Configuring Automatic Startup and Boot Order of VMs

March 17, 2024 Hyper-VPowerShellVirtualizationWindows Server 2016

Hyper-V: Configuring Automatic Startup and Boot Order of VMs

In Hyper-V, you can configure automatic startup and shutdown options for your virtual machines when you boot or restart your host OS. In this article, we’ll show how to configure the actions a Hyper-V host should take on virtual machines when it is powered on or shut down gracefully, and how to set the boot order of the virtual machines.

Contents:
  • Configure Automatic Startup and Shutdown Action for Hyper-V Virtual Machines
  • Boot (Startup) Order of Hyper-V Virtual Machines

Configure Automatic Startup and Shutdown Action for Hyper-V Virtual Machines

By default, a Hyper-V host saves the state of the registered virtual machines when restarted. It means that if a VM was running before a restart, Hyper-V will start it automatically. Automatic startup settings are configured for each VM individually.

Run the Hyper-V console, open the properties of any VM, and go to Settings -> Automatic Start Action. Three options to manage the automatic startup of a virtual machine are available:

  • Nothing – when a host is started, a virtual machine doesn’t start automatically (regardless of its state before the host restart)
  • Automatically start if it was running when the service stopped – a VM will automatically start only if it has been running before the host shutdown/restart
  • Always start this virtual machine automatically – always start this virtual machine when the Hyper-V host boots.

One more parameter is available for the last option – Startup Delay. Here you can specify the startup delay time for the virtual machine (in seconds). Using the delay, you can manage the boot order of your virtual machines (for example, to boot a domain controller before starting a VM with SQL Server), and reduce the load on the disk storage due to starting multiple VMs in turn.

hyper-v configure automatic strat action for virtual machine

It is interesting that there are no options in Windows Admin Center (WAC) to manage the automatic startup of Hyper-V virtual machines yet.

Also, in the Automatic Stop Action section, you can set what to do with your virtual machines if the host is shutdown or restarted.

The setting implies the correct restart of a Hyper-V host when virtual machines have time to shutdown gracefully, unlike emergency situations (unexpected power outage, BSOD).
  • Save the virtual machine state – a full state of a virtual machine is saved (including its memory). At the next startup, the virtual machine will resume from this point. Note that you must have additional free space on your disk to keep your VM memory (*.BIN files). The guest OS is not restarted;
  • Turn off the virtual machine – when a Hyper-V host is shutdown, a virtual machine will also be stopped (in the same way as a physical computer is shutdown). The VM state is not saved, a guest OS will be started with a full boot cycle. In this mode, there is some risk of getting inconsistent data in the apps running in the VM.
  • Shutdown the guest operating system – a guest OS is shutdown using Hyper-V integration service (graceful shutdown). All apps running in the VM are stopped and the risk of getting inconsistent data is very low.

Automatic Stop Action for Hyper-V VM

You can view and change the automatic startup and shutdown settings of your Hyper-V virtual machines using PowerShell.

Display the current startup and shutdown settings of all VMs:

Get-VM –VMname * | Select-Object VMname,AutomaticStartAction,AutomaticStartDelay,AutomaticStopAction

Hyper-V PowerShell - get startup and shutdown settings of VMs

You can change the automatic startup settings of a VM using the AutomaticStartAction option. Its possible values are Nothing, StartIfRunning, Start.

Get-VM –VMname lon-win10| Set-VM –AutomaticStartAction Start

You can use PowerShell to configure virtual machine settings on a free Windows Hyper-V Server host that has no GUI.

To set up startup delay for all VMs except for one (for example, a domain controller with FSMO roles):

Get-VM –VMname * | Where-object –FilterScript {$_.vmname –notlike “lon-dc*”} | Set-VM –AutomaticStartDelay 90

Using the –AutomaticStopAction option, you can set the VM shutdown settings (Save, TurnOff, ShutDown).

Boot (Startup) Order of Hyper-V Virtual Machines

When starting a standalone Hyper-V host, an administrator must manage the startup order of virtual machines on it. For example, you need the Exchange VM to boot only after the domain controller is available, and an app server to start after a database server. Hyper-V doesn’t have any built-in tools to manage startup order of the virtual machines, except for the start delay option (AutomaticStartDelay).

In the simplest cases, you can configure the order of VM startup by setting different startup delays for them:

Get-VM –VMname lon-dc01| Set-VM –AutomaticStartDelay 0
Get-VM –VMname lon-exch1,lon-db01 | Set-VM –AutomaticStartDelay 90
Get-VM –VMname lon-rds01,lon-app01 | Set-VM –AutomaticStartDelay 180

Another way is to start VMs in turn using a PowerShell startup script. In the script, you can set a delay before starting the next VM and perform additional checks for the availability of an application or service in the VM (to make sure that the app or service has been started). To make it more convenient, you can join several VMs into a group using tags. For example, I have set the following tags for the VMs:

set-vm lon-dc01,lon-dc02 -Notes "Boot order 1"
set-vm lon-exch1, lon-db01 -Notes "Boot order 2"
set-vm lon-rds01,lon-app01 -Notes "Boot order 3"

How to boot Hyper-V VMs in a specific order using Powershell script

The following PowerShell script starts virtual machines in a specific order and runs extra availability checks for some services (TCP ports) in the VM using the PowerShell cmdlet Test-NetConnection:

$VMtoStart = Get-VM | where notes -contains 'Boot order 1'
foreach ($cn in $VMtoStart)
{Start-VM $cn.name -asjob}
While (!(Test-NetConnection lon-dc01 -Port 445 -WarningAction SilentlyContinue).tcpTestSucceeded ){
Start-Sleep 30
}
$VMtoStart = Get-VM | where notes -contains 'Boot order 2'
foreach ($cn in $VMtoStart)
{Start-VM $cn.name -asjob}
While ((Test-NetConnection lon-exch1 -Port 25 -WarningAction SilentlyContinue).tcpTestSucceeded ){
Start-Sleep 30
}
$VMtoStart = Get-VM | where notes -contains 'Boot order 3'
foreach ($cn in $VMtoStart)
{Start-VM $cn.name -asjob}

Then add the PowerShell script to autostart or run it using the Task Scheduler (do not forget to disable automatic startup for all VMs that are started using this script). Remember that running PowerShell scripts is restricted in Windows by default. If needed, sign the PS1 script or change the PowerShell script execution policy.

0 comment
3
Facebook Twitter Google + Pinterest
previous post
How to Manually Import (Add) Update into WSUS from Microsoft Update Catalog
next post
How to Increase Attachment Size Limit in Outlook

Related Reading

View Windows Update History with PowerShell (CMD)

April 30, 2025

Uninstalling Windows Updates via CMD/PowerShell

April 18, 2025

Allowing Ping (ICMP Echo) Responses in Windows Firewall

April 15, 2025

How to Pause (Delay) Update Installation on Windows...

April 11, 2025

How to Write Logs to the Windows Event...

March 3, 2025

Leave a Comment Cancel Reply

join us telegram channel https://t.me/woshub
Join WindowsHub Telegram channel to get the latest updates!

Categories

  • Active Directory
  • Group Policies
  • Exchange Server
  • Microsoft 365
  • Azure
  • Windows 11
  • Windows 10
  • Windows Server 2022
  • Windows Server 2019
  • Windows Server 2016
  • PowerShell
  • VMware
  • Hyper-V
  • Linux
  • MS Office

Recent Posts

  • Cannot Install Network Adapter Drivers on Windows Server

    April 29, 2025
  • Change BIOS from Legacy to UEFI without Reinstalling Windows

    April 21, 2025
  • How to Prefer IPv4 over IPv6 in Windows Networks

    April 9, 2025
  • Load Drivers from WinPE or Recovery CMD

    March 26, 2025
  • How to Block Common (Weak) Passwords in Active Directory

    March 25, 2025
  • Fix: The referenced assembly could not be found error (0x80073701) on Windows

    March 17, 2025
  • Exclude a Specific User or Computer from Group Policy

    March 12, 2025
  • AD Domain Join: Computer Account Re-use Blocked

    March 11, 2025
  • How to Write Logs to the Windows Event Viewer from PowerShell/CMD

    March 3, 2025
  • How to Hide (Block) a Specific Windows Update

    February 25, 2025

Follow us

  • Facebook
  • Twitter
  • Telegram
Popular Posts
  • Hyper-V Virtual Machine Stuck in Stopping/Starting State
  • How to Install and Configure Free Hyper-V Server 2019/2016
  • Poor Network Performance on Hyper-V VMs in Windows Server 2019
  • How to Install Windows 11 on a Hyper-V Virtual Machine
  • Windows Cannot Find the Microsoft Software License Terms
  • USB Device Passthrough (Redirect) to Hyper-V Virtual Machine
  • Hyper-V: Enabling Routing Between Internal Networks (Subnets)
Footer Logo

@2014 - 2024 - Windows OS Hub. All about operating systems for sysadmins


Back To Top