In the previous blog post, we learnt how to create the Host Pools for Remote Apps Azure Virtual Desktop – PowerShell – Create a Host Pool, Application Group and Workspace for RemoteApp aka Published Applications | AskAresh and today we are going to create the host pool for Desktops. It’s an identical post to the RemoteApps only difference here will be specific input parameters will change to deliver the Desktop experience. We will deploy the following features within Azure Virtual Desktop using PowerShell:
- Create Host Pool with Type – Desktop
- Create the Application Group (AG)
- Create an Workspaces
- Assign the Azure Active Directory Group to the (AG)

I will break down the code block into smaller chunks first to explain the critical bits, and in the end, I will post the entire code block that can be run all at once. In this way, explaining block by block becomes easier than pasting one single block.
Desktop
Desktop – This is a way to provide end-users with a full Desktop experience along with the applications installed in the base image. Note this method is used for delivering non-persistent desktops as we are using pooled. If you want to provide persistence on top of these desktops you will have to leverage FSLogix.
Pre-requisites
Following are the pre-requisites before you begin
- PowerShell 5.1 and above
- Azure Subscription
- Permissions within the Azure Subscription for the creation of AVD – Host Pools
- Assumption
- You have an existing Resource Group (RG)
- Azure PowerShell Modules – Az.DesktopVirtualization
Sign to Azure
To start working with Azure PowerShell, sign in with your Azure credentials.
Connect-AzAccount
Variable Region
Delcare all the variable within this section. Lets take a look at what we are declaring within the script:
- Existing Resource Group within the Azure Subscription (AZ104-RG)
- A location where you are deploying this Host Pool (Australia East)
- Name of the Host Pool (D-HP01)
- Host Pool Type (Pooled) as it will be shared with multiple end-users
- Load balancing method for the Host Pool (DepthFirst)
- Maximum users per session host VM (10)
- The type of Application Group (Desktop). As we are providing full desktop experience.
- Application Group Name ($HPName-DAG)
- Workspace grouping name ($HPName-WRK01)
- Azure AD group that will be assigned to the application group (XXXX4b896-XXXX-XXXX-XXXX-33768d8XXXXX)
# Get existing context
$currentAzContext = Get-AzContext
# Your subscription. This command gets your current subscription
$subscriptionID = $currentAzContext.Subscription.Id
# Existing Resource Group to deploy the Host Pool
$rgName = "AZ104-RG"
# Geo Location to deploy the Host Pool
$location = "australiaeast"
# Host Pool name
$HPName = "D-HP01"
# Host Pool Type Pooled|Personal
$HPType = "Pooled"
# Host Pool Load Balancing BreadthFirst|DepthFirst|Persistent
$HPLBType = "DepthFirst"
# Max number or users per session host
$Maxusers = "10"
# Preffered App group type Desktop|RailApplications
$AppGrpType = "Desktop"
# ApplicationGroup Name
$AppGrpName = "$HPName-DAG"
# Workspace Name
$Wrkspace = "$HPName-WRK01"
# AAD Group used to assign the Application Group
# Copy the Object ID GUID from AAD Groups Blade
$AADGroupObjId = "XXXXXX-2f2d-XXXX-XXXX-33768d8XXXXX"
Execution block
Execution code block within this section. Lets take a look at what we are we executing within the script:
- Create the host pool with all the mentioned variables, tags and whether the validation enivornment yes/no.
- Create the application group and tie it to the host pool
- Finally, we create the workspace and tie it to the application group and hostpool
- Last step, we assign the AAD group object ID to the Application Group for all entitlement purposes.
# Create the Host Pool with Desktop Configurations
try
{
write-host "Create the Host Pool with Pooled Desktop Configurations"
$DeployHPWDesk = New-AzWvdHostPool -ResourceGroupName $rgName `
-SubscriptionId $subscriptionID `
-Name $HPName `
-Location $location `
-ValidationEnvironment:$true `
-HostPoolType $HPType `
-LoadBalancerType $HPLBType `
-MaxSessionLimit $Maxusers `
-PreferredAppGroupType $AppGrpType `
-Tag:@{"Billing" = "IT"; "Department" = "IT"; "Location" = "AUS-East" } `
-ErrorAction STOP
}
catch
{
Write-Host $_.Exception.Message -ForegroundColor Yellow
}
# Create the Application Group for the Desktop Host Pool
try
{
write-host "Create the Application Group for the Desktop Host Pool"
$CreateAppGroupDesk = New-AzWvdApplicationGroup -ResourceGroupName $rgName `
-Name $AppGrpName `
-Location $location `
-HostPoolArmPath $DeployHPWDesk.Id `
-ApplicationGroupType $AppGrpType `
-ErrorAction STOP
}
catch
{
Write-Host $_.Exception.Message -ForegroundColor Yellow
}
# Create the Workspace for the Desktop Host Pool
try
{
write-host "Create the Workspace for the Desktop Host Pool"
$CreateWorkspaceDesk = New-AzWvdWorkspace -ResourceGroupName $rgName `
-Name $Wrkspace `
-Location $location `
-ApplicationGroupReference $CreateAppGroupDesk.Id `
-ErrorAction STOP
}
catch
{
Write-Host $_.Exception.Message -ForegroundColor Yellow
}
# Assign the AAD group (Object ID) to the Application Group
try
{
write-host "Assigning the AAD Group to the Application Group"
$AssignAADGrpAG = New-AzRoleAssignment -ObjectId $AADGroupObjId `
-RoleDefinitionName "Desktop Virtualization User" `
-ResourceName $CreateAppGroupDesk.Name `
-ResourceGroupName $rgName `
-ResourceType 'Microsoft.DesktopVirtualization/applicationGroups' `
-ErrorAction STOP
}
catch
{
Write-Host $_.Exception.Message -ForegroundColor Yellow
}
Final Script
Here I will paste the entire script block for seamless execution in a single run. Following is the link to my GitHub for this script – avdwin365mem/createhp-ag-wk-DSK at main · askaresh/avdwin365mem (github.com)
# Connect to the Azure Subcription
Connect-AzAccount
# Get existing context
$currentAzContext = Get-AzContext
# Your subscription. This command gets your current subscription
$subscriptionID = $currentAzContext.Subscription.Id
# Existing Resource Group to deploy the Host Pool
$rgName = "AZ104-RG"
# Geo Location to deploy the Host Pool
$location = "australiaeast"
# Host Pool name
$HPName = "D-HP01"
# Host Pool Type Pooled|Personal
$HPType = "Pooled"
# Host Pool Load Balancing BreadthFirst|DepthFirst|Persistent
$HPLBType = "DepthFirst"
# Max number or users per session host
$Maxusers = "10"
# Preffered App group type Desktop|RailApplications
$AppGrpType = "Desktop"
# ApplicationGroup Name
$AppGrpName = "$HPName-DAG"
# Workspace Name
$Wrkspace = "$HPName-WRK01"
# AAD Group used to assign the Application Group
# Copy the Object ID GUID from AAD Groups Blade
$AADGroupObjId = "dccXXXXX-2f2d-XXXX-XXXX-33768d8bXXXX"
# Create the Host Pool with Desktop Configurations
try
{
write-host "Create the Host Pool with Pooled Desktop Configurations"
$DeployHPWDesk = New-AzWvdHostPool -ResourceGroupName $rgName `
-SubscriptionId $subscriptionID `
-Name $HPName `
-Location $location `
-ValidationEnvironment:$true `
-HostPoolType $HPType `
-LoadBalancerType $HPLBType `
-MaxSessionLimit $Maxusers `
-PreferredAppGroupType $AppGrpType `
-Tag:@{"Billing" = "IT"; "Department" = "IT"; "Location" = "AUS-East" } `
-ErrorAction STOP
}
catch
{
Write-Host $_.Exception.Message -ForegroundColor Yellow
}
# Create the Application Group for the Desktop Host Pool
try
{
write-host "Create the Application Group for the Desktop Host Pool"
$CreateAppGroupDesk = New-AzWvdApplicationGroup -ResourceGroupName $rgName `
-Name $AppGrpName `
-Location $location `
-HostPoolArmPath $DeployHPWDesk.Id `
-ApplicationGroupType $AppGrpType `
-ErrorAction STOP
}
catch
{
Write-Host $_.Exception.Message -ForegroundColor Yellow
}
# Create the Workspace for the Desktop Host Pool
try
{
write-host "Create the Workspace for the Desktop Host Pool"
$CreateWorkspaceDesk = New-AzWvdWorkspace -ResourceGroupName $rgName `
-Name $Wrkspace `
-Location $location `
-ApplicationGroupReference $CreateAppGroupDesk.Id `
-ErrorAction STOP
}
catch
{
Write-Host $_.Exception.Message -ForegroundColor Yellow
}
# Assign the AAD group (Object ID) to the Application Group
try
{
write-host "Assigning the AAD Group to the Application Group"
$AssignAADGrpAG = New-AzRoleAssignment -ObjectId $AADGroupObjId `
-RoleDefinitionName "Desktop Virtualization User" `
-ResourceName $CreateAppGroupDesk.Name `
-ResourceGroupName $rgName `
-ResourceType 'Microsoft.DesktopVirtualization/applicationGroups' `
-ErrorAction STOP
}
catch
{
Write-Host $_.Exception.Message -ForegroundColor Yellow
}
Next Steps on the Host Pool
Now that the host pool, application group and workspaces are ready following are the next steps involved:
- Generate a registration token
- Add the session host virtual machine to the host pool
I hope you will find this helpful information for deploying a host pools, application group and workspaces within Azure Virtual Desktop. If you want to see a Powershell version of the adding the session host activities, leave me a comment below or on my socials. Please let me know if I have missed any steps or details, and I will be happy to update the post.
Thanks,
Aresh Sarkari
Recent Comments