如果用户已存在,Add-AzureADGroupMember将失败。

时间:2017-01-10 11:43:46

标签: azure azure-active-directory

https://docs.microsoft.com/en-us/powershell/azuread/v2/add-azureadgroupmember

如果用户已存在,则

Add-AzureADGroupMember失败。如何抑制错误?我试图用"忽略"传递-ErrorAction参数。或者" SilentlyContinue"但它没有帮助!

命令就像

Add-AzureADGroupMember -ObjectId $NewAzureADGroup.ObjectId -RefObjectId $userInformation.ObjectId 

1 个答案:

答案 0 :(得分:0)

您可以将该参数包装在“Try”“Catch”块中:

Try {
Add-AzureADGroupMember -ObjectId $NewAzureADGroup.ObjectId -RefObjectId $userInformation.ObjectId
}
Catch
{
Write-Host "User Already Present in Group"
}

否则,您可以提交错误报告on GitHub