If you are looking for a way to remove a user's membership on all M365 groups, you could import the following script:
In Coreview:
{ "id": "1eba1dd4-e697-42b7-85d8-85acdd40e2c5", "title": "Exchange - Remove a user from all M365 groups", "description": "Remove a user's complete memberships from all M365 groups", "lastModified": "2022-05-16T13:11:59.3820000Z", "target": "None", "tags": [], "vars": [ { "name": "UserPrincipalName", "type": "string", "isRequired": true } ], "params": [], "columns": {}, "version": 4, "statement": "param ([string]$UserPrincipalName)\r\n\r\n$user = Get-AzureADUser -ObjectId $UserPrincipalName\n\n$memberships = Get-AzureADUserMembership -ObjectId $user.ObjectId | Where-Object {$_.ObjectType -eq \"Group\"}\n\nForEach ($group in $memberships){\n Remove-AzureADGroupMember -ObjectId $group.ObjectId -MemberId $user.ObjectId\n}" }
Was this article helpful?
That’s Great!
Thank you for your feedback
Sorry! We couldn't be helpful
Thank you for your feedback
Feedback sent
We appreciate your effort and will try to fix the article