Use Azure CLI and Azure PowerShell with Azure Virtual Desktop

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:

Example commands

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.

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 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.

Next steps

Now that you know how to use Azure CLI and Azure PowerShell with Azure Virtual Desktop, here are some articles that use them: