Adding bulk users to Azure Windows Virtual Desktop using PowerShell

Since the release of Azure Windows Virtual Desktop, organizations are finding it a bit difficult to manage the environment. It is because Azure Portal does not provide a management pane that could be used to execute daily operational tasks such as adding users, logging off users, removing users, and so on. There are many other tasks that a Windows Virtual Desktop admin would like to perform every day, such as adding and removing bulk users from the WVD tenant. For example, you might have given temporary permissions to some users in the WVD environment and would like to remove these users on a daily or weekly basis. This is where this article comes handy. In this article, we are going to talk about some examples of using Azure Windows Virtual Desktop PowerShell modules to add a single user or bulk users.

Before you start to use the PowerShell commands explained in this article, install WVD PowerShell modules by executing the command below. Note that you will be required to execute the PowerShell command from an elevated PowerShell prompt.

Install-Module -Name RDInfra.RDPowershell

Once the PowerShell modules have been installed, run Import-Module Microsoft.RDInfra.RDPowershell so all WVD related PowerShell commands can be imported in the current PowerShell session.

You need to connect to your WVD tenant before executing PowerShell commands to add a single user or bulk users by running this command:

Add-RdsAccount -DeploymentUrl ""

Use of Add-RdsAppGroupUser PowerShell cmdlet

In this article, we are explaining the use of the Add-RDSAppGroupUser PowerShell cmdlet to add a single user or bulk users. Note that you will be required to provide the inputs below to the Add-RdsAppGroupUser PowerShell cmdlet:

  • Tenant name: The WVD tenant name.
  • Host pool name: The WVD post pool name to which the user will be added.
  • User principal name: The name of the UPN that is present on the WVD tenant.

For example, executing the PowerShell command below will add user to the host pool named: TechGenixPool in the WVD tenant named TechGenixWVD

Add-RdsAppGroupUser -TenantName "TechGenixWVD" -HostPoolName "TechGenixPool" -AppGroupName "Desktop Application Group" -UserPrincipalName ""

Note that the above command processes the request and does not show the result. Usually, PowerShell cmdlets return information to let users know that a command has been successful, but this is not the case with the Add-RDSAppGroupUser cmdlet. To ensure the user was added to the WVD tenant, executing this PowerShell command will help you get the status:

Get-RdsAppGroupUser -TenantName "TechGenixWVD" -HostPoolName "TechGenixPool" -AppGroupName "Desktop Application Group" -UserPrincipalName " "

Adding bulk users to WVD tenant

If you would like to add bulk users to WVD tenant from a CSV file, we can use the same PowerShell commands explained in this article, but make use of ForEach loop. The ForEach loop will help us process all entries in a CSV file. Let’s assume we create a file called UPNs.CSV file. The UPNs.CSV file contains user principal names on each line. If we need to add all users from a CSV file to the WVD tenant, we can use this PowerShell script:

$UPNFile = "C:\Temp\UPNs.CSV"
$ResultFile = "C:\Temp\Result.CSV"
Remove-item $ResultFile -ErrorAction SilentlyContinue
$STR = "User Principal Name, Status"
$CSV = Import-CSV $UPNFile
$TenantName = "TechGenixWVD"
$HostPool = "TechGenixHostPool"
ForEach ($Item in $CSV)
$ThisUser = $Item.UPN
Write-Host "Processing User: " $ThisUser
Add-RdsAppGroupUser -TenantName $TenantName -HostPoolName $HostPool -AppGroupName "Desktop Application Group" -UserPrincipalName $ThisUser
IF ($Error.Count -eq 0)
$STR = $ThisUser+", Added"
Add-Content $ResultFile $STR
$STR = $ThisUser+", Error Adding User"
Add-Content $ResultFile $STR
Write-Host "Finished Processing all users..."

Before you execute the PowerShell script, you are required to make these necessary changes:

  • Create a CSV file named C:\Temp\UPNs.CSV and mention all User Principal Names that you wish to add.
  • Change $TenantName and $HostPool variables accordingly.

Once you have executed the PowerShell script, you will see a report generated in the C:\Temp folder. The report file name will be Result.CSV. The Result.CSV contains the status for each user, for example, whether the addition was successful or not.

Tip: As you can see, as part of the above script, I am using $Error variable to see if any issues were reported when executing the Add-RDSAppGroupUser command. The error will always report ZERO ($Error.Count -eq 0) if there were no issues in running the command.

The PowerShell script was retrieved from Wintellisys WVD Manager, which can be used to add and remove bulk users easily from within the application as seen in the screenshot below:

The Wintellisys WVD Manager console allows you to add and remove a single user or bulk users. You just need to provide the path to CSV file, which contains the list of users to added. As you can see in the screenshot above, it can also report on users that were not added successfully in the “Failed” section and users that were added successfully in the “Added” section.

Removing users from Azure Windows Virtual Desktop tenant

When it comes to removing the users from the WVD tenant, you can use Remove-RDSAppGroupUser PowerShell cmdlet. For example, to remove a single user from WVD Tenant, executing below PowerShell command will do:

Remove-RdsAppGroupUser -TenantName "TechGenixWVD" -HostPoolName "TechGenixPool" -AppGroupName "Desktop Application Group" -UserPrincipalName " "

And if you would like to remove multiple users, you can always make use of the PowerShell script explained to add the users. You will just be required to replace “Add-RDSAppGroupUser” with “Remove-RDSAppGroupUser” PowerShell cmdlet.

Featured image: Shutterstock

Nirmal Sharma

Nirmal Sharma is a MCSEx3, MCITP and was awarded the Microsoft MVP award in Directory Services and Windows Networking. He specializes in Microsoft Azure, Office 365, Directory Services, Failover Clusters, Hyper-V, PowerShell Scripting and System Center products. Nirmal has been involved with Microsoft Technologies since 1994. In his spare time, he likes to help others and share some of his knowledge by writing tips and articles on various sites.

Published by
Nirmal Sharma

Recent Posts

Microsoft Teams guest access: How to enable and manage it

Two of the main factors that affect the total cost of an organization’s Microsoft 365…

8 hours ago

Samsung Galaxy Unpacked 2020: Everything you need to know

Samsung rolled out the all-new Galaxy Z Fold 2, Note 20, Note 20 Ultra handsets…

12 hours ago

SAN vs. NAS: Detailed comparison of these two storage technologies

SAN and NAS provide dedicated storage for a group of users using completely different approaches…

15 hours ago

Generation 1 virtual machines: Modernize them and bring them up to date

In many companies, Generation 1 virtual machines have been superseded by Gen 2 VMs. But…

1 day ago

Free VPNs from Hong Kong with ‘no-log policy’ experience data leak

With these free VPNs based in Hong Kong, you may not be paying any money…

1 day ago

Azure DevOps tips and tricks: Using built-in features

These Azure DevOps tips and tricks come fresh from the field where they have been…

2 days ago