Concepts

Azure Virtual Desktop (formerly known as Windows Virtual Desktop) is a comprehensive desktop and app virtualization service that runs on the cloud. It enables organizations to securely deliver virtualized Windows desktops and applications to end users from any location. In this article, we will explore how to automate the creation of Azure Virtual Desktop hosts and host pools by using PowerShell, Azure CLI, Azure Resource Manager templates (ARM templates), and Bicep.

1. Azure PowerShell

Azure PowerShell provides a command-line interface for managing Azure resources. To automate the creation of Azure Virtual Desktop hosts and host pools using PowerShell, follow these steps:

  • Step 1: Install Azure PowerShell module:
  • Install-Module -Name Az -AllowClobber -Scope CurrentUser

  • Step 2: Connect to Azure:
  • Connect-AzAccount

  • Step 3: Create a resource group:
  • New-AzResourceGroup -Name "MyResourceGroup" -Location "East US"

  • Step 4: Create a host pool:
  • $hostPool = New-AzWvdHostPool -Name "MyHostPool" -ResourceGroupName "MyResourceGroup" -Location "East US" -FriendlyName "My Host Pool" -RegistrationInfo @{"RegistrationTokenOperationMode"="QuickSetup"} -MaxSessionLimit 10

  • Step 5: Create a host pool VM:
  • $vmName = "MyVM"
    $vmSize = "Standard_D2s_v3"
    $osDiskSizeInGB = 128
    $numberOfInstances = 2

    New-AzWvdSessionHost -HostPoolName $hostPool.Name -ResourceGroupName $hostPool.ResourceGroupName -Location $hostPool.Location -Name $vmName -VmSize $vmSize -OsDiskSizeInGB $osDiskSizeInGB -ApplicationGroupReferenceType Desktop -DesktopVirtualizationEnvironmentId $hostPool.DefaultDesktopVirtualizationEnvironmentId -NumberOfInstances $numberOfInstances

2. Azure CLI

Azure CLI is an alternative command-line interface to manage Azure resources. To automate the creation of Azure Virtual Desktop hosts and host pools using Azure CLI, follow these steps:

  • Step 1: Install Azure CLI:
  • sudo apt-get install azure-cli

  • Step 2: Sign in to Azure:
  • az login

  • Step 3: Create a resource group:
  • az group create --name MyResourceGroup --location eastus

  • Step 4: Create a host pool:
  • az desktopvirtualization hostpool create --resource-group MyResourceGroup --name MyHostPool --location eastus --friendly-name "My Host Pool" --registration-info "{\"registrationTokenOperationMode\":\"QuickSetup\"}" --max-session-limit 10

  • Step 5: Create a host pool VM:
  • az desktopvirtualization sessionhost create --resource-group MyResourceGroup --name MyVM --location eastus --virtual-machine-profile "{\"size\":\"Standard_D2s_v3\",\"osDiskSizeInGB\":128}" --application-group-reference-type Desktop --desktop-virtualization-environment-id --number-of-instances 2

3. Azure Resource Manager (ARM) Templates

ARM templates provide a declarative way to define the desired state of Azure resources. To automate the creation of Azure Virtual Desktop hosts and host pools using ARM templates, follow these steps:

  • Step 1: Create an ARM template file (e.g., azuredeploy.json) with the desired configuration:
  • {
    "$schema": "https://schema.management.azure.com/schemas/2019-04-01/deploymentTemplate.json#",
    "contentVersion": "1.0.0.0",
    "resources": [
    {
    "type": "Microsoft.DesktopVirtualization/hostPools",
    "name": "MyHostPool",
    "apiVersion": "2021-07-12-preview",
    "location": "East US",
    "properties": {
    "friendlyName": "My Host Pool",
    "registrationInfo": {
    "registrationTokenOperationMode": "QuickSetup"
    },
    "maxSessionLimit": 10
    }
    },
    {
    "type": "Microsoft.DesktopVirtualization/hostPools/sessionHosts",
    "name": "MyVM",
    "apiVersion": "2021-07-12-preview",
    "location": "East US",
    "dependsOn": [
    "[resourceId('Microsoft.DesktopVirtualization/hostPools', 'MyHostPool')]"
    ],
    "properties": {
    "vmTemplate": {
    "osDisk": {
    "diskSizeGB": 128
    },
    "vmType": "Standard_D2s_v3"
    },
    "applicationGroupReferenceType": "Desktop",
    "desktopVirtualizationEnvironmentId": "[reference(resourceId('Microsoft.DesktopVirtualization/hostPools', 'MyHostPool'), '2021-07-12-preview').defaultDesktopVirtualizationEnvironmentId]",
    "numberOfInstances": 2
    }
    }
    ]
    }

  • Step 2: Deploy the ARM template using PowerShell or Azure CLI:
  • New-AzResourceGroupDeployment -ResourceGroupName "MyResourceGroup" -TemplateFile "azuredeploy.json"
    az deployment group create --resource-group MyResourceGroup --template-file azuredeploy.json

4. Bicep

Bicep is a domain-specific language for deploying Azure resources. It simplifies the creation and management of Azure resources. To automate the creation of Azure Virtual Desktop hosts and host pools using Bicep, follow these steps:

  • Step 1: Create a Bicep file (e.g., main.bicep) with the desired configuration:
  • param resourceName string = 'MyResourceGroup'
    param resourceLocation string = 'East US'

    resource hostPool 'Microsoft.DesktopVirtualization/hostPools@2021-07-12-preview' = {
    name: 'MyHostPool'
    location: resourceLocation
    properties: {
    friendlyName: 'My Host Pool'
    registrationInfo: {
    registrationTokenOperationMode: 'QuickSetup'
    }
    maxSessionLimit: 10
    }
    }

    resource sessionHost 'Microsoft.DesktopVirtualization/hostPools/sessionHosts@2021-07-12-preview' = {
    name: 'MyVM'
    location: resourceLocation
    dependsOn: [hostPool]
    properties: {
    vmTemplate: {
    osDisk: {
    diskSizeGB: 128
    }
    vmType: 'Standard_D2s_v3'
    }
    applicationGroupReferenceType: 'Desktop'
    desktopVirtualizationEnvironmentId: hostPool.defaultDesktopVirtualizationEnvironmentId
    numberOfInstances: 2
    }
    }

  • Step 2: Deploy the Bicep file using PowerShell or Azure CLI:
  • New-AzResourceGroupDeployment -ResourceGroupName "MyResourceGroup" -TemplateFile "main.bicep"
    az deployment group create --resource-group MyResourceGroup --template-file main.bicep

By automating the creation of Azure Virtual Desktop hosts and host pools, you can streamline your deployment processes and ensure consistent configurations. Choose the automation method that suits your requirements and leverage the power of scripting and templates to accelerate your Azure Virtual Desktop implementation.

Answer the Questions in Comment Section

Which tool can you use to automate the creation of Azure Virtual Desktop hosts and host pools?

a) PowerShell
b) Azure CLI
c) Azure Resource Manager templates (ARM templates)
d) Bicep
e) All of the above

Answer: e) All of the above

True or False: PowerShell can be used to automate the creation of Azure Virtual Desktop hosts and host pools.

Answer: True

Which of the following tools are command-line interfaces that can be used to automate the creation of Azure Virtual Desktop hosts and host pools? (Select all that apply)

a) PowerShell
b) Azure CLI
c) Azure Resource Manager templates (ARM templates)
d) Bicep

Answer: a) PowerShell, b) Azure CLI

What is the primary purpose of Azure Resource Manager templates (ARM templates)?

a) To automate the deployment of Azure resources
b) To automate the creation of Virtual Desktop hosts and host pools
c) To manage and configure Azure Virtual Desktop
d) To create custom images for Virtual Desktop environments

Answer: a) To automate the deployment of Azure resources

True or False: Azure Resource Manager templates (ARM templates) can be used to automate the creation of Azure Virtual Desktop host pools.

Answer: True

Which tool provides a declarative way to define Azure resources and their dependencies?

a) Azure Resource Manager templates (ARM templates)
b) Bicep
c) Azure CLI
d) PowerShell

Answer: a) Azure Resource Manager templates (ARM templates)

What is Bicep?

a) A domain-specific language for deploying Azure resources
b) A tool for managing Azure Virtual Desktop
c) A scripting language used in Azure automation
d) A tool for creating custom images for Virtual Desktop environments

Answer: a) A domain-specific language for deploying Azure resources

True or False: Bicep can be used to automate the creation of Azure Virtual Desktop hosts and host pools.

Answer: True

Which tool uses a JSON-based language to define the desired state of Azure resources?

a) Azure Resource Manager templates (ARM templates)
b) Bicep
c) Azure CLI
d) PowerShell

Answer: a) Azure Resource Manager templates (ARM templates)

What is the purpose of automating the creation of Azure Virtual Desktop hosts and host pools?

a) To simplify the management and provisioning of virtual desktop infrastructure
b) To enhance security and compliance in virtual desktop environments
c) To enable efficient scaling and deployment of virtual desktops
d) All of the above

Answer: d) All of the above

0 0 votes
Article Rating
Subscribe
Notify of
guest
22 Comments
Oldest
Newest Most Voted
Inline Feedbacks
View all comments
Marlyse Le Gall
8 months ago

Great blog post! Automating Azure Virtual Desktop (AVD) setup using ARM templates saved us a huge amount of time.

Oliver Ma
1 year ago

Thanks for this! We’ve been manually creating our AVD hosts, and this will streamline our workflow a lot.

Herman Graham
11 months ago

I’ve found the Azure CLI to be the fastest way for scriptable deployments. Anyone else using CLI over PowerShell?

Lois Walker
11 months ago

Bicep templates have significantly reduced the complexity of our deployment scripts. Highly recommend over ARM templates.

Soncevida Antonovich
9 months ago

For newcomers, I suggest starting with Azure Resource Manager templates before moving to Bicep for better understanding of the structures.

Toivo Ramo
1 year ago

How do you handle role-based access control (RBAC) for AVD host pools in your scripts?

Živojin Kićanović

Automation with PowerShell has improved our deployment times drastically. We can spin up a new pool within minutes now.

Alexandra Fleury
1 year ago

I’m experiencing intermittent errors when deploying with ARM templates. Anyone else face this?

22
0
Would love your thoughts, please comment.x
()
x