P Tomer
P Tomer

Reputation: 1

Add-AzureADGroupMember fails if user already exist.

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

Add-AzureADGroupMember fails if user already exist. how to suppress error? I have tried to pass -ErrorAction parameters with "Ignore" or "SilentlyContinue" but it does not help!

command is like

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

Upvotes: 0

Views: 2301

Answers (1)

Shawn Tabrizi
Shawn Tabrizi

Reputation: 12434

You could wrap that argument in a "Try" "Catch" block:

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

Otherwise you can submit a bug report on GitHub.

Upvotes: 2

Related Questions