0

I want to add multiple users to my app group at a time, is there someone know how to user loop powershell to do that?

The Add-RdsAppGroupUser cmdlet as below can assigns a user to access the specified app group. This cmdlet only takes in a single user principal name (UPN) at a time and only applies to users (not groups).

Add-RdsAppGroupUser -TenantName "contoso" -HostPoolName "contosoHostPool" -AppGroupName "Desktop Application Group" -UserPrincipalName "user1@contoso.com"

For example: I have 1000 users from user1@contoso.com to user1000@contoso.com, what should I write the code and how can i check the result after I finish it.

4

1 回答 1

1

这是这个想法的演示。我无权访问您使用的 cmdlet,因此循环显示其结果参数 splat。

#region >>> fake getting a list of users
#    in real life, use Get-Content or some other method
$UserList = @(
    'One@contoso.com'
    'Two@contoso.com'
    'Three@contoso.com'
    'Four@contoso.com'
    'Five@contoso.com'
    )
#endregion >>> fake getting a list of users

foreach ($UL_Item in $UserList)
    {
    # the following structure is called "Splatting"
    #    it puts some - or all - the parameters into a hashtable
    #    that can be fed to the cmdlet by replacing the "$" with an "@"
    $ARAGU_Params = @{
        TenantName = "contoso"
        HostPoolName = "contosoHostPool"
        AppGroupName = "Desktop Application Group"
        UserPrincipalName = $UL_Item
        }
    #Add-RdsAppGroupUser @ARAGU_Params

    # i don't have the above cmdlet, so this is just showing the parameters & values being passed to it
    $ARAGU_Params
    '=' * 30
    }

输出 ...

Name                           Value
----                           -----
HostPoolName                   contosoHostPool
UserPrincipalName              One@contoso.com
TenantName                     contoso
AppGroupName                   Desktop Application Group
==============================
HostPoolName                   contosoHostPool
UserPrincipalName              Two@contoso.com
TenantName                     contoso
AppGroupName                   Desktop Application Group
==============================
HostPoolName                   contosoHostPool
UserPrincipalName              Three@contoso.com
TenantName                     contoso
AppGroupName                   Desktop Application Group
==============================
HostPoolName                   contosoHostPool
UserPrincipalName              Four@contoso.com
TenantName                     contoso
AppGroupName                   Desktop Application Group
==============================
HostPoolName                   contosoHostPool
UserPrincipalName              Five@contoso.com
TenantName                     contoso
AppGroupName                   Desktop Application Group
==============================
于 2020-02-26T02:12:06.593 回答