Add multiple users to WVD App Group

<#
Author: Kevin Pas
Date: 16-10-2020
Title: Add multiple users to WVD App Group
Description: With the script below you can read a txt file with the email addresses of the people who need to be added to the app group.

#>

$UserNames = Get-Content “C:\Temp\Users.txt”
$TenantName = “contoso”
$HostPoolName = “contosoHostPool”
$AppGroupName = “contosoAppGroupName”
$GetCurrentUsers = (Get-RdsAppGroupUser -TenantName $TenantName -HostPoolName $HostPoolName -AppGroupName $AppGroupName).UserPrincipalName

ForEach ($User in $UserNames) {
if($GetCurrentUsers -eq $User){

Write-Host “$User is already member of the app group”

}
else{
Write-Host “$User is added to the app group”
Add-RdsAppGroupUser -TenantName $TenantName -HostPoolName $HostPoolName -AppGroupName $AppGroupName -UserPrincipalName $user
}
}
Write-Host “`nThe persons below are now members of the app group”
Get-RdsAppGroupUser -TenantName $TenantName -HostPoolName $HostPoolName -AppGroupName $AppGroupName | ft UserPrincipalName