Home > OS >  How to add user assigned identity to AAD group with Powershell?
How to add user assigned identity to AAD group with Powershell?

Time:12-01

I am able to add service principals and individual users to Azure Active Directory group with command:

Add-AzADGroupMember -TargetGroupObjectId GROUPID -MemberObjectId MEMBERID

I'm giving the user assigned managed identity principal id from the portal as MemberObjectId. I suppose the ID is something else, but what it is and how to get it? I have tried client id as well, with no luck.

When I try to run the same command with user assigned managed id, it fails with the error:

Line | 143 | Az.MSGraph.internal\New-AzADGroupGraphRefMember @PSBoundP … | ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ | Resource 'XXXXX-...' does not exist or one of its queried reference-property objects | are not present.



CodePudding user response:

I tried to reproduce the same in my environment and got below results

I have one User Assigned Managed Identity named UserassignedMI like below:

enter image description here

To add the above identity to Azure AD group, I ran the same command as you by giving Client ID and got same error as below:

Add-AzADGroupMember -TargetGroupObjectId <GroupID> -MemberObjectId <Client ID>

Response:

enter image description here

But when I used Object (principal) ID for -MemberObjectID, it worked and gave results successfully like below:

Add-AzADGroupMember -TargetGroupObjectId <GroupID> -MemberObjectId <Object (principal) ID>
Get-AzADGroupMember -GroupObjectId <GroupID>

Response:

enter image description here

When I checked the same in Portal, managed identity added to the group successfully like below:

enter image description here

  • Related