Forum Discussion

venka91's avatar
venka91
Copper Contributor
Feb 04, 2022

Add-AzureADGroupMember not working

Hi there,

 

I am trying to add a user to Azure AD Security Group. I see the Object ID and Reference ID are correct but still i am getting error. Can anyone please assist.

 

echo "Adding License ..."
Install-Module AzureAd
Import-Module AzureAd
Connect-AzureAD
$RefObj = (Get-AzureADGroup -SearchString 'Office365_EnableMail').ObjectID
$UserObj = (Get-AzureADUser -ObjectID $email).ObjectID
Add-AzureADGroupMember -RefObjectId $RefObj -ObjectId $UserObj

 

 

My Output:

PS C:\Windows\system32> $RefObj
97333e85-0f37-453a-b390-04d4ea6d3467

 

PS C:\Windows\system32> $UserObj
fda17b03-9abd-43c3-8865-baecc296c18c

 

PS C:\Windows\system32> Add-AzureADGroupMember -RefObjectId $RefObj -ObjectId $UserObj
Add-AzureADGroupMember : Error occurred while executing AddGroupMember
Code: Request_ResourceNotFound
Message: Resource 'fda17b03-9abd-43c3-8865-baecc296c18c' does not exist or one of its queried reference-property objects are not
present.
RequestId: 3f77eb5d-36b7-44ae-9c4f-8d512c4fe5cb
DateTimeStamp: Fri, 04 Feb 2022 06:39:06 GMT
HttpStatusCode: NotFound
HttpStatusDescription: Not Found
HttpResponseStatus: Completed
At line:1 char:1
+ Add-AzureADGroupMember -RefObjectId $RefObj -ObjectId $UserObj
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : NotSpecified: (:) [Add-AzureADGroupMember], ApiException
+ FullyQualifiedErrorId : Microsoft.Open.AzureAD16.Client.ApiException,Microsoft.Open.AzureAD16.PowerShell.AddGroupMember

  • It's the other way around mate, -ObjectId should be the group one.
  • It's the other way around mate, -ObjectId should be the group one.

Resources