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

Azure 如何使用loop powershell分配多个用户访问应用程序组?,azure,powershell,azure-active-directory,wvd,Azure,Powershell,Azure Active Directory,Wvd,我想一次向我的应用程序组添加多个用户,是否有人知道如何使用powershell循环来完成此操作 如下所示的Add-RdsAppGroupUser cmdlet可以分配用户访问指定的应用程序组。 此cmdlet一次仅接受一个用户主体名称(UPN),并且仅适用于用户(而不是组) 例如:我有1000个来自的用户user1@contoso.com到user1000@contoso.com,我应该写什么代码,完成后如何检查结果。这里是这个想法的演示。我无权访问您使用的cmdlet,因此循环显示其结果参数s

我想一次向我的应用程序组添加多个用户,是否有人知道如何使用powershell循环来完成此操作

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


例如:我有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
==============================

将您的用户列表存储在$Var中—很可能是一个数组。然后用
foreach
对其进行迭代,并替换您的
-UserPrincipalName“user1@contoso.com“
带有
-UserPrincipalName”$CurrentUserFromList”
。如果您需要的数据位于该项的属性中,您可能需要展开该项。@Lee_Dailey您能给我一个示例代码吗?很抱歉,我不太了解powershell。非常感谢。请看我贴的答案。如果你有问题,请问。。。但现在快睡觉了,所以我的反应可能会延迟。。。非常感谢你的演示,我现在能理解了。顺便问一下,你有什么建议吗?#在现实生活中,使用获取内容或其他方法,因为我必须添加1000多个用户。@Arthur-非常欢迎你![grin]您可能可以为用户查询Active Directory设置。结果可能会给你类似于
$UL_Item.UPN
的东西,而不是我使用的一个简单的
$UL_Item
。@Arthur-非常欢迎你!祝你好运。。。嗨,李,谢谢你的建议,我发现它运行得很好。顺便问一下,你能看看我的另一篇文章吗?如何自动更改csv文件中的循环Powershell内容?希望你能帮助我实现这个目标。@Arthur-我去看看…[咧嘴笑]
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
==============================