Windows OS Hub
  • Windows Server
    • Windows Server 2022
    • Windows Server 2019
    • Windows Server 2016
    • Windows Server 2012 R2
    • Windows Server 2012
    • 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 2012
    • 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

August 20, 2021 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

Create Organizational Units (OU) Structure in Active Directory...

May 17, 2022

Windows Security Won’t Open or Shows a Blank...

May 17, 2022

How to Manually Install Windows Updates from CAB...

May 16, 2022

RDS and RemoteApp Performance Issues on Windows Server...

May 16, 2022

Deploying Software (MSI Packages) Using Group Policy

May 12, 2022

Leave a Comment Cancel Reply

Categories

  • Active Directory
  • Group Policies
  • Exchange Server
  • Microsoft 365
  • Azure
  • Windows 11
  • Windows 10
  • Windows 7
  • Windows Server 2019
  • Windows Server 2016
  • Windows Server 2012 R2
  • PowerShell
  • VMWare
  • Hyper-V
  • MS Office

Recent Posts

  • Create Organizational Units (OU) Structure in Active Directory with PowerShell

    May 17, 2022
  • Windows Security Won’t Open or Shows a Blank Screen on Windows 10/ 11

    May 17, 2022
  • How to Manually Install Windows Updates from CAB and MSU Files?

    May 16, 2022
  • RDS and RemoteApp Performance Issues on Windows Server 2019/2016

    May 16, 2022
  • Deploying Software (MSI Packages) Using Group Policy

    May 12, 2022
  • Updating VMware ESXi Host from the Command Line

    May 11, 2022
  • Enable or Disable MFA for Users in Azure/Microsoft 365

    April 27, 2022
  • Fix: You’ll Need a New App to Open This Windows Defender Link

    April 27, 2022
  • How to Reset an Active Directory User Password with PowerShell and ADUC?

    April 27, 2022
  • How to Completely Uninstall Previous Versions of Office with Removal Scripts?

    April 26, 2022

Follow us

woshub.com

ad

  • Facebook
  • Twitter
  • RSS
Popular Posts
  • How to Stop/Kill a Stuck Virtual Machine on Hyper-V?
  • How to Install and Configure Free Hyper-V Server 2019/2016?
  • USB Device Passthrough (Redirect) to Hyper-V Virtual Machine
  • Poor Network Performance on Hyper-V VMs in Windows Server 2019
  • Windows Cannot Find the Microsoft Software License Terms
  • How to Install Windows 11 on a Hyper-V Virtual Machine?
  • Import, Export and Clone Virtual Machines in Hyper-V
Footer Logo

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


Back To Top