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:

DEVRel46/VMWVDDEVRel46-2.nielskok.tech

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:

VMWVDDEVRel46-2.nielskok.tech

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!

References

Microsoft docs about update-wvdsessionhost

Split array in Powershell

Blog about Azure information Protection



Related Posts