我试图通过UPN更新CSV文件中多个用户的AzureADGroupMember。
这就是我遇到并尝试过的:
$users = Import-csv "C:\Temp\testgroup2.csv"
$users | ForEach-Object{
Add-AzureGroupADGroupMember -ObjectId xcv9890-stest999-xcvxc234-xcv2342324
-RefObjectId (Get-AzureADUser -ObjectId $_.UPN).ObjectId
}我得到以下两个错误。
Import-csv : The member "Role" is already present.
At line:1 char:10
Get-AzureADUser : Cannot bind argument to parameter 'ObjectId' because it
is null.
At line:4 char:120知道为什么会这样吗?我真的很感谢你的帮助。
谢谢,
发布于 2019-04-17 06:29:30
因为您没有提供.csv文件,所以我可以给您一个在我这边工作的解决方案。
首先,让我们检查这两个错误。
导入-csv:成员“角色”已经存在。
我可以重现这个问题,这意味着您的.csv文件有两列标题“角色”,只需将其修改为正确的格式。


Get-AzureADUser :不能将参数'ObjectId‘绑定参数,因为它是null。
这意味着这个部分$_.UPN是空的,这可能是由第一个错误引起的。
我的样本
testgroup.csv
UPN,Role
leeliu@xxxxxx.onmicrosoft.com,role1
test@xxxxxx.onmicrosoft.com,role2

脚本(您应该使用Add-AzureADGroupMember,而不是Add-AzureGroupADGroupMember):
$users = Import-csv "C:\Users\joyw\Desktop\testgroup.csv"
$users | ForEach-Object{
Add-AzureADGroupMember -ObjectId 9d42xxxxxx28b600ad -RefObjectId (Get-AzureADUser -ObjectId $_.UPN).ObjectId
}注意事项:在运行脚本之前,需要确保用户尚未在组中,否则将得到一个One or more added object references already exist for the following modified properties: 'members'错误。
https://stackoverflow.com/questions/55719575
复制相似问题