如何使用loop powershell分配多个用户访问一个应用组?

How to use loop powershell to assign multiple users to access an app group?

我想一次将多个用户添加到我的应用程序组,有人知道如何使用用户循环 powershell 来做到这一点吗?

如下所示的Add-RdsAppGroupUser cmdlet 可以分配一个用户访问指定的应用程序组。 此 cmdlet 一次仅接受一个用户主体名称 (UPN),并且仅适用于用户(而非组)。

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

例如:我有1000个用户,从user1@contoso.com到user1000@contoso.com,代码应该怎么写,写完后怎么查看结果

这里是这个想法的演示。我无权访问您使用的 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
==============================