Automating Management of Host Pools, Session Hosts, and User Sessions by Using PowerShell and Azure Command-Line Interface (CLI)
Automating Management of Host Pools, Session Hosts, and User Sessions by Using PowerShell and Azure Command-Line Interface (CLI)

An important aspect of any Azure Virtual Desktop (AVD) environment is ensuring you automate management of the environment where you can. To get the most out of this cloud-hosted service, it is important to ensure you are utilizing automation to limit the amount of time spent doing manual tasks. This will give a much better experience for your users and administrators. From an automation perspective, you can utilize Azure native services to facilitate automating daily management tasks which will minimize manual intervention by admins.

This course will help you plan and automate management tasks for your Azure Virtual Desktop and help you understand how it integrates with other Azure native automation services.

Learning Objectives

  • Configure automation for Azure Virtual Desktop
  • Automate management of host pools, session hosts, and user sessions by using PowerShell and Azure Command Line Interface (CLI)
  • Implement autoscaling in host pools

Intended Audience

This course is intended for anyone who wants to become an Azure Virtual Desktop Specialist and/or those preparing to take the AZ-140 exam. 


If you wish to get the most out of this course, it is recommended that you have a good understanding of Azure administration, although it's not essential.


Welcome to this module on automating management of host pools, session hosts, and user sessions by using PowerShell, and Azure Command-Line Interface (CLI).  In this module, we will cover the following topics:

  • Automating host pools, session hosts, and user sessions with PowerShell
  • Automating host pools, session hosts, and user sessions with Azure Command-line interface (CLI)

Let’s start off by doing a walk-through demo of configuring automation tasks with PowerShell.

Here we have PowerShell open with Administrative privileges. The first step we need to complete is to ensure we have the relevant module installed to allow us to run the AVD Powershell cmdlets.  In our case, we need to install the ‘Az.DesktopVirtualization’ module.  We can select Yes for the warnings that appear, and then we are ready to connect and authenticate to the Azure portal.

We use the ‘Connect-AzAccount’ cmdlet to initiate the connection, and then enter our global administrative credentials in the pop-up box to authenticate.  We are now logged into our tenant and ready to manage the AVD environment.

The first command we will look at is ‘Get-AzWvdHostPool’ which outputs relevant information regarding our AVD host pool.  We need to specify the host pool name and the resource group it is stored in. The output then shows you all the relevant information about that specific host pool, including location, an Identity Type if you have set one, and any plan details if you are using one.  The Get cmdlet will always retrieve information about the relevant resource you have specified and will not make any changes.

Another Get cmdlet we can use when managing AVD is ‘Get-AzWvdDesktop’ which will show us relevant information about a specific desktop application we have set up.  You need to specify the resource group, application group name, and the name of the desktop application you need information about.

Let's now look at a cmdlet that will make an actual change to our environment.  In this cmdlet we are going to remove an application group, so we use the cmdlet called ‘Remove-AzWvdApplicaitonGroup’.  As you can see we need to specify the resource group again, and the name of the application group we want to remove.  

The final cmdlet I want to show is one to update an existing resource within AVD.  We need to use an update cmdlet, in our case we are going to utilize the ‘Update-AzWvdHostPool’ cmdlet to update an existing host pool.  As you can see there are a number of settings we can update.  In our case, the only one that will be different is that we are changing the MaxSessionLimit from 5 to 6.

We are now going to do a walk-through demo of configuring automation tasks with Azure CLI.

We are launching the Azure CLI from the Azure portal, therefore need to navigate to the URL.  As we are already authenticated from logging into the Azure portal we do not need to authenticate again when launching the Azure CLI.

The first command type we are going to use is one that lists specific resources within our AVD environment.  List commands are very similar to ‘Get’ cmdlets in PowerShell.  As you can see in this command, we want to list all the information about our application group called ‘Desktop’ within our resource group.  There is a whole host of details that are shown as part of the output, including the application group type, location, and the object ID.

So we can get a clear view of the output, I have re-launched the Azure CLI.  The next command I want to look at is similar to the list command, in that it does not make any changes and simply outputs information about a specific resource.  It is the ‘show’ command.  In our example, we want to show information regarding the application group called ‘ITGEEK-DT01’.  Again as you can see a number of details are shown in the output, very similar to the list command output.

One clever feature of the Azure CLI is that it will not let you delete resources if other resources already exist within it.  In this example we are trying to delete a host pool, however, because an application group exists within that which needs to be deleted first, we get an error giving us that information.

About the Author

Shabaz Darr is a Senior Infrastructure Specialist at Netcompany based in the UK. He has 15 years plus experience working in the IT industry, 7 of those he has spent working with Microsoft Cloud Technologies in general, with a focus on MEM and IaaS. Shabaz is a Microsoft MVP in Enterprise Mobility with certifications in Azure Administration and Azure Virtual Desktop. During his time working with Microsoft Cloud, Shabaz has helped multiple public and private sector clients in the UK with designing and implementing secure Azure Virtual Desktop environments.