|
| 1 | +--- |
| 2 | +title: Use Azure CLI and Azure PowerShell with Azure Virtual Desktop |
| 3 | +description: Learn about Azure CLI and Azure PowerShell with Azure Virtual Desktop and some useful example commands you can run. |
| 4 | +ms.topic: how-to |
| 5 | +author: dknappettmsft |
| 6 | +ms.author: daknappe |
| 7 | +ms.date: 02/01/2023 |
| 8 | +--- |
| 9 | +# Use Azure CLI and Azure PowerShell with Azure Virtual Desktop |
| 10 | + |
| 11 | +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](/cli/azure/what-is-azure-cli) and [Azure PowerShell](/powershell/azure/what-is-azure-powershell), which cover a wide range of Azure services. |
| 12 | + |
| 13 | +This article explains how you can use the Azure CLI extension and an Azure PowerShell module, and provides some useful example commands. |
| 14 | + |
| 15 | +## Azure CLI extension and Azure PowerShell module |
| 16 | + |
| 17 | +Here are the names of the Azure CLI extension and Azure PowerShell module, and links to our reference documentation: |
| 18 | + |
| 19 | +- Azure CLI: [`az desktopvirtualization`](/cli/azure/desktopvirtualization) |
| 20 | + |
| 21 | +- Azure PowerShell: [`Az.DesktopVirtualization`](/powershell/module/az.desktopvirtualization) |
| 22 | + |
| 23 | +Both Azure CLI and Azure PowerShell are available to use in the [Azure Cloud Shell](../cloud-shell/overview.md) natively in the Azure portal with no installation, or you can install them locally on your device for Windows, macOS, and Linux. |
| 24 | + |
| 25 | +To learn how to install Azure CLI and Azure PowerShell across all supported platforms, see the following links: |
| 26 | + |
| 27 | +- Azure CLI: [How to install the Azure CLI](/cli/azure/install-azure-cli) |
| 28 | + |
| 29 | +- Azure PowerShell: [Install the Azure Az PowerShell module](/powershell/azure/install-az-ps) |
| 30 | + |
| 31 | +## Example commands |
| 32 | + |
| 33 | +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. |
| 34 | + |
| 35 | +# [Azure CLI](#tab/cli) |
| 36 | + |
| 37 | +> [!IMPORTANT] |
| 38 | +> In the following examples, you'll need to change the `<placeholder>` values for your own. |
| 39 | +
|
| 40 | +### Available Azure regions |
| 41 | + |
| 42 | +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: |
| 43 | + |
| 44 | +```azurepowershell |
| 45 | +az account list-locations --query "sort_by([].{DisplayName:displayName, Location:name}, &Location)" -o table |
| 46 | +``` |
| 47 | + |
| 48 | +### Retrieve the object ID of a host pool, workspace, application group, or application |
| 49 | + |
| 50 | +- To retrieve the object ID of a host pool, run the following command: |
| 51 | + |
| 52 | + ```azurecli |
| 53 | + az desktopvirtualization hostpool show \ |
| 54 | + --name <Name> \ |
| 55 | + --resource-group <ResourceGroupName> \ |
| 56 | + --query objectId |
| 57 | + --output tsv |
| 58 | + ``` |
| 59 | + |
| 60 | +- To retrieve the object ID of a workspace, run the following command: |
| 61 | + |
| 62 | + ```azurecli |
| 63 | + az desktopvirtualization workspace show \ |
| 64 | + --name <Name> \ |
| 65 | + --resource-group <ResourceGroupName> \ |
| 66 | + --query objectId |
| 67 | + --output tsv |
| 68 | + ``` |
| 69 | + |
| 70 | +- To retrieve the object ID of an application group, run the following command: |
| 71 | + |
| 72 | + ```azurecli |
| 73 | + az desktopvirtualization applicationgroup show \ |
| 74 | + --name <Name> \ |
| 75 | + --resource-group <ResourceGroupName> \ |
| 76 | + --query objectId |
| 77 | + --output tsv |
| 78 | + ``` |
| 79 | + |
| 80 | +> [!TIP] |
| 81 | +> The Azure CLI extension for Azure Virtual Desktop doesn't have commands for applications. Use Azure PowerShell instead. |
| 82 | +
|
| 83 | +# [Azure PowerShell](#tab/powershell) |
| 84 | + |
| 85 | +> [!IMPORTANT] |
| 86 | +> In the following examples, you'll need to change the `<placeholder>` values for your own. |
| 87 | +
|
| 88 | +### Available Azure regions |
| 89 | + |
| 90 | +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: |
| 91 | + |
| 92 | +```azurepowershell |
| 93 | +Get-AzLocation | Sort-Object DisplayName | FT DisplayName, Location |
| 94 | +``` |
| 95 | + |
| 96 | +### Retrieve the object ID of a host pool, workspace, application group, or application |
| 97 | + |
| 98 | +Some PowerShell cmdlets require you to provide the object ID of Azure Virtual Desktop service objects. Here are some examples: |
| 99 | + |
| 100 | +- To retrieve the object ID of a host pool, run the following command: |
| 101 | + |
| 102 | + ```azurepowershell |
| 103 | + (Get-AzWvdHostPool -Name <HostPoolName> -ResourceGroupName <ResourceGroupName>).ObjectId |
| 104 | + ``` |
| 105 | + |
| 106 | +- To retrieve the object ID of a workspace, run the following command: |
| 107 | + |
| 108 | + ```azurepowershell |
| 109 | + (Get-AzWvdWorkspace -Name <WorkspaceName> -ResourceGroupName <ResourceGroupName>).ObjectID |
| 110 | + ``` |
| 111 | + |
| 112 | +- To retrieve the object ID of an application group, run the following command: |
| 113 | + |
| 114 | + ```azurepowershell |
| 115 | + (Get-AzWvdApplicationGroup -Name <ApplicationGroupName> -ResourceGroupName <ResourceGroupName>).ObjectId |
| 116 | + ``` |
| 117 | + |
| 118 | +- To retrieve the object ID of a desktop application, run the following command: |
| 119 | + |
| 120 | + ```azurepowershell |
| 121 | + (Get-AzWvdDesktop -Name <DesktopName> -ApplicationGroupName <ApplicationGroupName> -ResourceGroupName <ResourceGroupName>).ObjectId |
| 122 | + ``` |
| 123 | + |
| 124 | +- To retrieve the object IDs of all RemoteApp applications in an application group, run the following command: |
| 125 | + |
| 126 | + ```azurepowershell |
| 127 | + Get-AzWvdApplication -ApplicationGroupName <ApplicationGroupName> -ResourceGroupName <ResourceGroupName> | FT Name, FilePath, ObjectId |
| 128 | + ``` |
| 129 | + |
| 130 | +--- |
| 131 | + |
| 132 | +## Next steps |
| 133 | + |
| 134 | +Now that you know how to use Azure CLI and Azure PowerShell with Azure Virtual Desktop, here are some articles that use them: |
| 135 | + |
| 136 | +- [Create an Azure Virtual Desktop host pool with PowerShell or the Azure CLI](create-host-pools-powershell.md) |
| 137 | +- [Manage app groups using PowerShell or the Azure CLI](manage-app-groups-powershell.md) |
0 commit comments