title | description | ms.topic | ms.custom | author | ms.author | ms.date |
---|---|---|---|---|---|---|
Use Azure CLI and Azure PowerShell with Azure Virtual Desktop |
Learn about Azure CLI and Azure PowerShell with Azure Virtual Desktop and some useful example commands you can run. |
how-to |
devx-track-azurepowershell, devx-track-azurecli, docs_inherited |
dknappettmsft |
daknappe |
01/08/2024 |
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.
Here are the names of the Azure CLI extension and Azure PowerShell module, and links to our reference documentation:
-
Azure CLI:
az desktopvirtualization
-
Azure PowerShell:
Az.DesktopVirtualization
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:
-
Azure CLI: How to install the Azure CLI
-
Azure PowerShell: Install the Azure Az PowerShell module
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.
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
-
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.
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
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:
(Get-AzWvdHostPool -Name <HostPoolName> -ResourceGroupName <ResourceGroupName>).ObjectId
-
To retrieve the object ID of a workspace, run the following command:
(Get-AzWvdWorkspace -Name <WorkspaceName> -ResourceGroupName <ResourceGroupName>).ObjectID
-
To retrieve the object ID of an application group, run the following command:
(Get-AzWvdApplicationGroup -Name <ApplicationGroupName> -ResourceGroupName <ResourceGroupName>).ObjectId
-
To retrieve the object ID of a desktop application, run the following command:
(Get-AzWvdDesktop -Name <DesktopName> -ApplicationGroupName <ApplicationGroupName> -ResourceGroupName <ResourceGroupName>).ObjectId
-
To retrieve the object IDs of all RemoteApp applications in an application group, run the following command:
Get-AzWvdApplication -ApplicationGroupName <ApplicationGroupName> -ResourceGroupName <ResourceGroupName> | Select-Object Name, FilePath, ObjectId
Now that you know how to use Azure CLI and Azure PowerShell with Azure Virtual Desktop, here are some articles that use them:
- Create an Azure Virtual Desktop host pool with PowerShell or the Azure CLI
- Manage application groups using PowerShell or the Azure CLI
- For the full PowerShell reference documentation, see Az.DesktopVirtualization.