azure - Powershell : Using variables when trying to add users to group

标签 azure azure-powershell azure-ad-powershell-v2

我一直在尝试找到一种从变量将用户批量添加到组的方法。
我创建我的变量。
测试我的变量。然后当我使用它们时,系统会以我意想不到的方式解释它们。有人知道如何最好地自动化这个过程吗?

PS C:\WINDOWS\system32> $user = get-MsolUser | Select ObjectID
PS C:\WINDOWS\system32> $user

ObjectId
--------
97232511-7ea5-4f26-9372-************
baa75007-e0fc-4265-b17c-************


PS C:\WINDOWS\system32> $group = get-MsolGroup -ObjectId 776da14a-9c10-4dd1-b880-************ | Select ObjectID
PS C:\WINDOWS\system32> $group

ObjectId
--------
776da14a-9c10-4dd1-b880-************


PS C:\WINDOWS\system32> Add-MsolGroupMember -GroupObjectID $group -GroupMemberType User -GroupMemberObjectId $user
Add-MsolGroupMember : Cannot bind parameter 'GroupObjectId'. Cannot convert the "@{ObjectId=776da14a-9c10-4dd1-b880-d0646d49e926}"
value of type "Selected.Microsoft.Online.Administration.Group" to type "System.Guid".
At line:1 char:36
+ Add-MsolGroupMember -GroupObjectID $group -GroupMemberType User -Grou ...
+                                    ~~~~~~
+ CategoryInfo          : InvalidArgument: (:) [Add-MsolGroupMember],     ParameterBindingException
+ FullyQualifiedErrorId : CannotConvertArgumentNoMessage,Microsoft.Online.Administration.Automation.AddGroupMember

PS C:\WINDOWS\system32>

最佳答案

在选择一个组时尝试此操作,然后将其传递给 Add-MsolGroupMember cmdlet。

$group = get-MsolGroup -ObjectId 776da14a-9c10-4dd1-b880-************ | Select-Object -ExpandProperty ObjectID

关于azure - Powershell : Using variables when trying to add users to group,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/51624976/

相关文章:

c# - Azure AD Multi-Tenancy 权限

powershell - Azure Powershell 工作流 - 未找到输入参数

azure - 管道从 azure 工件恢复 nuget 包

Azure DSC 初学者 - 入门问题

Azure PowerShell 任务找不到文件路径

c# - Azure powershell 无法识别 "azure"

azure - Get-MsolUserRole Azure AD V2 cmdlet 等效项

azure - 如何使用 PowerShell 添加 Azure-AD 设备对象的扩展属性?

azure - az acr - 如果单个帐户有多个订阅,则无法找到存储库