Last active
April 29, 2019 09:07
-
-
Save OmerMicrosoft/4e0085c7633a6f2b2c89a77ef4ea3040 to your computer and use it in GitHub Desktop.
Initialize the setup of Windows Virtual Desktop in Azure by assigning the 'TenantCreator' role to a selected user and creating the WVD tenant
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<#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: https://rdweb.wvd.microsoft.com/ | |
#> | |
###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 | |
###Main### | |
$Credentials = Get-Credential | |
$AzureAccount = Add-AzAccount -Credential $Credentials | |
if (-not $AzureAccount) { | |
Write-Host "Could not get Azure account information. Abort" -ForegroundColor Red | |
break | |
} | |
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 | |
break | |
} | |
#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 = "https://rdbroker.wvd.microsoft.com" | |
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