Skip to content

Instantly share code, notes, and snippets.

What would you like to do?
Initialize the setup of Windows Virtual Desktop in Azure by assigning the 'TenantCreator' role to a selected user and creating the WVD tenant
<#Script Summary:
This PowerShell script initialize the setup of Windows Virtual Desktop in Azure.
The script include:
1.Assign the “TenantCreator” role to a user account.
2.Create a Windows Virtual Desktop tenant.
Before running this script, you should allow the Windows Virtual Desktop service to access Azure AD on the following link:
###Install and import Required Modules###
#Install-Module Az,AzureAD,Microsoft.RDInfra.RDPowerShell -AllowClobber -Force #Remove remark if the required modules have not been installed yet.
Import-Module Az,Microsoft.RDInfra.RDPowerShell,AzureAD -Force
$Credentials = Get-Credential
$AzureAccount = Add-AzAccount -Credential $Credentials
if (-not $AzureAccount) {
Write-Host "Could not get Azure account information. Abort" -ForegroundColor Red
Connect-AzAccount -Credential $Credentials
#Selecting Azure subscription to host the RDS tenant
Write-Host "Getting Azure subscription data... Please wait." -ForegroundColor Green
$SelectedAzureSubscription = Get-AzSubscription | Select-Object SubscriptionId, Name, TenantId | Out-GridView -Title "Select the Azure subscription and tenant you would like to use" -OutputMode Single
if (-not $SelectedAzureSubscription) {
Write-Host "Could not get Azure subscription details. Abort" -ForegroundColor Red
#Assigning the current user with the 'TenantCreator' role
Connect-AzureAD -Credential $Credentials
$WVDApplication = Get-AzureADServicePrincipal -Filter "displayName eq 'Windows Virtual Desktop'"
$ApplicationRole = $WVDApplication.AppRoles | Where-Object {$_.DisplayName -eq 'TenantCreator'}
$AzureADUser = Get-AzADUser -UserPrincipalName $AzureAccount.Context.Account
New-AzureADUserAppRoleAssignment -ObjectId $AzureADUser.Id -PrincipalId $AzureADUser.Id -ResourceId $WVDApplication.ObjectId -Id $ApplicationRole.Id
#Creating the RDS Tenant
$BrokerURL = ""
Add-RdsAccount -DeploymentUrl $BrokerURL -Credential $Credentials
$RDSTenantName = Read-Host "Enter RDS tenant name"
$NewRDSTenant = New-RdsTenant -Name $RDSTenantName -AadTenantId $SelectedAzureSubscription.TenantId -AzureSubscriptionId $SelectedAzureSubscription.SubscriptionId
if ($NewRDSTenant) {
Write-Host "A new RDS tenant was created with the name $($NewRDSTenant.TenantName)" -ForegroundColor Green
else {
Write-Host "The creation of a new RDS tenant was failed." -ForegroundColor Red
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment