https://docs.microsoft.com/en-us/powershell/azuread/v2/add-azureadgroupmember
如果用户已存在,则Add-AzureADGroupMember失败。如何抑制错误?我试图用"忽略"传递-ErrorAction参数。或者" SilentlyContinue"但它没有帮助!
命令就像
Add-AzureADGroupMember -ObjectId $NewAzureADGroup.ObjectId -RefObjectId $userInformation.ObjectId
答案 0 :(得分:0)
您可以将该参数包装在“Try”“Catch”块中:
Try {
Add-AzureADGroupMember -ObjectId $NewAzureADGroup.ObjectId -RefObjectId $userInformation.ObjectId
}
Catch
{
Write-Host "User Already Present in Group"
}
否则,您可以提交错误报告on GitHub。