Windows OS Hub
  • Windows Server
    • Windows Server 2022
    • Windows Server 2019
    • Windows Server 2016
    • Windows Server 2012 R2
    • Windows Server 2008 R2
    • SCCM
  • Active Directory
    • Active Directory Domain Services (AD DS)
    • Group Policies
  • Windows Clients
    • Windows 11
    • Windows 10
    • Windows 8
    • Windows 7
    • Windows XP
    • MS Office
    • Outlook
  • Virtualization
    • VMWare
    • Hyper-V
    • KVM
  • PowerShell
  • Exchange
  • Cloud
    • Azure
    • Microsoft 365
    • Office 365
  • Linux
    • CentOS
    • RHEL
    • Ubuntu
  • Home
  • About

Windows OS Hub

  • Windows Server
    • Windows Server 2022
    • Windows Server 2019
    • Windows Server 2016
    • Windows Server 2012 R2
    • Windows Server 2008 R2
    • SCCM
  • Active Directory
    • Active Directory Domain Services (AD DS)
    • Group Policies
  • Windows Clients
    • Windows 11
    • Windows 10
    • Windows 8
    • Windows 7
    • Windows XP
    • MS Office
    • Outlook
  • Virtualization
    • VMWare
    • Hyper-V
    • KVM
  • PowerShell
  • Exchange
  • Cloud
    • Azure
    • Microsoft 365
    • Office 365
  • Linux
    • CentOS
    • RHEL
    • Ubuntu

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

March 15, 2022 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
2
Facebook Twitter Google + Pinterest
previous post
How to Manually Import (Add) Update into WSUS from Microsoft Update Catalog?
next post
Fix: Windows Stuck at “Preparing to Configure Windows”

Related Reading

How to Connect VPN Before Windows Logon

November 14, 2023

Send Emails with Microsoft Graph API and PowerShell

November 6, 2023

Zabbix: How to Get Data from PowerShell Scripts

October 27, 2023

Tracking Printer Usage with Windows Event Viewer Logs

October 19, 2023

PowerShell: Configure Certificate-Based Authentication for Exchange Online (Azure)

October 15, 2023

Leave a Comment Cancel Reply

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

  • How to Connect VPN Before Windows Logon

    November 14, 2023
  • Removing Azure Arc Setup Feature on Windows Server 2022

    November 9, 2023
  • Using WPAD (Web Proxy Auto-Discovery Protocol) on Windows

    November 7, 2023
  • Send Emails with Microsoft Graph API and PowerShell

    November 6, 2023
  • Zabbix: How to Get Data from PowerShell Scripts

    October 27, 2023
  • Tracking Printer Usage with Windows Event Viewer Logs

    October 19, 2023
  • PowerShell: Configure Certificate-Based Authentication for Exchange Online (Azure)

    October 15, 2023
  • Reset Root Password in VMware ESXi

    October 12, 2023
  • How to Query and Change Teams User Presence Status with PowerShell

    October 8, 2023
  • How to Increase Size of Disk Partition in Ubuntu

    October 5, 2023

Follow us

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

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


Back To Top