Forum Discussion
How to Remove Members from Microsoft 365 Groups with PowerShell
To remove members from Microsoft 365 Groups using PowerShell, particularly Microsoft 365 (Unified) Groups, it’s best to use the Microsoft Graph PowerShell SDK. After connecting to Graph with the Connect-MgGraph command and proper permissions (GroupMember.ReadWrite.All), you can retrieve the group ID using Get-MgGroup, and the user's ID with Get-MgUser. From there, Remove-MgGroupMemberByRef lets you safely remove the user. However, it’s essential to first check if the person is an owner—especially the only owner—using Get-MgGroupOwner. If so, you’ll need to assign a new owner with Add-MgGroupOwnerByRef before proceeding to avoid orphaning the group. For traditional mail-enabled security or distribution groups, you can use Exchange Online PowerShell’s Remove-DistributionGroupMember. These precautions help maintain group integrity while streamlining member management.
That's a nice AI-generated summary of the article...