This is a blogpost about a script to set drain mode for all session hosts via powershell in one WVD hostpool. This is a script for the spring release. The fall release CMDLets of WVD uses other CMDlets.

WVD Script

Firstly, we need to connect to Azure using Powershell. We can do this by using the following command:

After that you need to make sure you are using the correct Azure subscription in context. You can make sure by using this command:

Next, we can run the “WVD set drain mode Powershell script”:

The update-AzWvdSessionHost CMDlet is used. You can read more about it here.

When you run the script the output is shown per Session Host and looks like this:

WVD set drain mode powershell output

The for-each loop shown in the script example is somewhat special and needs some explanation. This the for-each loop:

We need to split the array that contains the string which is the name of the WVD Sessionhost. The original name of this value is. For example:


When you use this to disallow session you will see this error:

Error for setting drain mode in powershell

We need to make sure that only this name remains:

So we need to split the array at the “/”. We are achieving this by using this piece of code:

This puts the hostname of the WVD Session Host in the “$WVDArray[1]” array to make sure the correct name is selected and can be found as a session host.

After this you can add this script in to your Azure DevOps configuration to help you simplify your WVD Deployment!


Microsoft docs about update-wvdsessionhost

Split array in Powershell

Blog about Azure information Protection

Related Posts

8 thoughts on “WVD Set Drain Mode Powershell

  1. Pingback: essay

Leave a Reply

Your email address will not be published. Required fields are marked *