How To Drain Mode Azure Virtual Desktop Hosts With PowerShell

This Microsoft Azure Virtual Desktop blog post will show you how to host in drain mode.

Drain Mode

The Drain Mode feature in Azure Virtual Desktop allows us to place a hold on new sessions and only allow existing sessions to run on the host.

It is recommended to put a host in maintenance mode before doing planned maintenance (restart) and redirecting a new session to a different host.

Install AVD PowerShell Module

Before we start, we need to install the AVD PowerShell module using the following cmdlet.

Install-Module -Name Az.DesktopVirtualization

Once the module is installed, run the cmdlet below to connect to Azure.


Enter Drain Mode

Run the cmdlet below to place a host in Dran Mode mode.

Update-AzWvdSessionHost -ResourceGroupName RGNAME  -HostPoolName HOSTPULNAME   -Name SERVER  -AllowNewSession:$false

Update the cmdlet with:

  • Resource Group Name
  • Host Pool Name
  • Server Name

To exit Drain Mode change the -AllowNewSession:$false to -AllowNewSession:$true

Multiple Servers

To place multiple AVD hosts in Drain Mode using the code below.

$servers = "server1", "servr2", "server3"
foreach( $server in $servers )
Update-AzWvdSessionHost -ResourceGroupName RGNAME  -HostPoolName HOSTPOOL  -Name $server  -AllowNewSession:$false


Success! You're on the list.