Forum Discussion
Kav777
May 13, 2023Copper Contributor
Modify MS 365 unified group membership using PowerShell with Enterprise app authentication
Im trying to run the following command: Add-UnifiedGroupLinks -Identity 'email address removed for privacy reasons' -LinkType members -Links kavehtest114@gelion.com However, the error I am getting ...
VasilMichev
May 13, 2023MVP
You can use the Graph endpoints/cmdlets instead.
Kav777
May 15, 2023Copper Contributor
Thanks managed to find graph cmdlets rather than making invoke-webrequest calls (wanted to avoid the latter), ended up with this:
To add a member:
New-MgGroupMember -GroupId $GroupID -DirectoryObjectId $UserID
To remove a member:
Remove-MgGroupMemberByRef -DirectoryObjectId $UserID -GroupId $GroupId
'$UserID' is the 'id' attribute thats returned from 'Get-MgUser' and '$GroupID' is the 'Guid' attribute returned from 'Get-MgGroup'.
To add a member:
New-MgGroupMember -GroupId $GroupID -DirectoryObjectId $UserID
To remove a member:
Remove-MgGroupMemberByRef -DirectoryObjectId $UserID -GroupId $GroupId
'$UserID' is the 'id' attribute thats returned from 'Get-MgUser' and '$GroupID' is the 'Guid' attribute returned from 'Get-MgGroup'.