Use Azure CLI and Azure PowerShell with Azure Virtual Desktop
Article
There's an Azure CLI extension and an Azure PowerShell module for Azure Virtual Desktop that you can use to create, update, delete, and interact with Azure Virtual Desktop service objects as alternatives to using the Azure portal. They're part of Azure CLI and Azure PowerShell, which cover a wide range of Azure services.
This article explains how you can use the Azure CLI extension and an Azure PowerShell module, and provides some useful example commands.
Azure CLI extension and Azure PowerShell module
Here are the names of the Azure CLI extension and Azure PowerShell module, and links to our reference documentation:
Both Azure CLI and Azure PowerShell are available to use in the Azure Cloud Shell natively in the Azure portal with no installation, or you can install them locally on your device for Windows, macOS, and Linux.
To learn how to install Azure CLI and Azure PowerShell across all supported platforms, see the following links:
Here are some example commands you can use to get information and values about your Azure Virtual Desktop resources you might find useful. Select the relevant tab for your scenario.
In the following examples, you'll need to change the <placeholder> values for your own.
Available Azure regions
When creating Azure Virtual Desktop service objects using any of the CLI commands that contain create, you need to specify the Azure region you want to create them in. To find the name of the Azure region to use with the --location parameter, run the following command and use a value from the Location column:
az account list-locations --query "sort_by([].{DisplayName:displayName, Location:name}, &Location)" -o table
Retrieve the object ID of a host pool, workspace, application group, or application
To retrieve the object ID of a host pool, run the following command:
az desktopvirtualization hostpool show \
--name <Name> \
--resource-group <ResourceGroupName> \
--query objectId
--output tsv
To retrieve the object ID of a workspace, run the following command:
az desktopvirtualization workspace show \
--name <Name> \
--resource-group <ResourceGroupName> \
--query objectId
--output tsv
To retrieve the object ID of an application group, run the following command:
az desktopvirtualization applicationgroup show \
--name <Name> \
--resource-group <ResourceGroupName> \
--query objectId
--output tsv
Tip
The Azure CLI extension for Azure Virtual Desktop doesn't have commands for applications. Use Azure PowerShell instead.
Important
In the following examples, you'll need to change the <placeholder> values for your own.
Available Azure regions
When creating Azure Virtual Desktop service objects using any of the PowerShell cmdlets that begin New-AzWvd..., you need to specify the Azure region you want to create them in. To find the name of the Azure region to use with the -Location parameter, run the following command and use a value from the Location column:
Get-AzLocation | Sort-Object DisplayName | FT DisplayName, Location
Retrieve the object ID of a host pool, workspace, application group, or application
Some PowerShell cmdlets require you to provide the object ID of Azure Virtual Desktop service objects. Here are some examples:
To retrieve the object ID of a host pool, run the following command:
Azure Virtual Desktop on Microsoft Azure is a desktop and app virtualization service that runs on the cloud. Azure Virtual Desktop works across devices – including Windows, Mac, iOS, and Android – with full-featured apps that you can use to access remote desktops and apps.