What it is
A PowerShell sample that removes users from the Microsoft 365 group behind a Viva Engage community, one group and user per CSV row, through Microsoft Graph. It removes access to the listed communities only; it does not delete the user's account or remove them from any other community. Removal can't be undone by the script. It runs as a dry run by default ($whatIfMode = $true).
Why use it
- Remove many users from communities in one run.
- Preview the removals first;
$whatIfModeis$trueby default. - Resolves each user's object ID from the email address in the CSV for you.
How to use it
- Create a Microsoft Entra app registration with the Microsoft Graph
Group.ReadWrite.Allapplication permission and grant admin consent. - Create a CSV with a
GroupIDcolumn (the Microsoft 365 group ID behind the community) and anEmailcolumn (the user to remove), one pair per row. - Set
$usersToBeDeletedCSV,$ClientId,$TenantId, and$ClientSecretnear the top of the script. - Run with the default
$whatIfMode = $trueand review the output. Set it to$falseonly when you are sure. - Run:
.\Delete-EngageUsers.ps1Prerequisites
- Test in a non-production tenant first; removals can't be undone by the script
- Microsoft Entra app registration with the Group.ReadWrite.All application permission and admin consent
- CSV with GroupID and Email columns; GroupID is the Microsoft 365 group GUID behind the community