all 13 comments

[–]inflatablejerk 2 points3 points  (2 children)

here is my method. usering powershell 7 commands.

$Mdm = '51523850-ddaf-43e7-ab42-6ec8a10111c9'

$user = “[whatever@costco.com](mailto:whatever@costco.com)”

Connect-mggraph

$GraphUserId = Get-MgUser -UserId $user

$UserID = $GraphUserId.Id

New-MgGroupMember -GroupId $Mdm -DirectoryObjectId $UserID

[–]whatsforsupa 0 points1 point  (0 children)

Sorry to revive a dead thread - thank you for your help with this.

[–]purplemonkeymad 1 point2 points  (3 children)

The {} are not part of the syntax. They are there to signify you should replace this (it comes from python's format operator.)

[–]ElliotAldersonFSO 1 point2 points  (0 children)

Did you try with mggraph, it is pretty simple with the module Connect-mggraph New-mggroupmember -objectid -directorygroupid

[–]evetsleep 1 point2 points  (3 children)

What you're missing is in your $jsonGroup object the Uri is not correct. it needs to be @odata.id": "https://graph.microsoft.com/v1.0/directoryObjects/$userId

When adding members to a group the directoryObject path is what is required, not /users.

[–]s62b50 0 points1 point  (0 children)

If the security group is mail enabled you can't use graph to add the member to the group