I recently had to decommission an Office 365 account that required removing all contacts, groups and 3000+ unlicensed users, and then purging the deleted users.
First, DirSync was disabled to avoid conflict with any accounts that have Active Directory as their source of authority.
Second, to run deletions in bulk we must connect to Office 365 via the Azure AD PowerShell module.
Next, and after a little review of the users, the following commands where run.
To remove all unlicensed users from Office 365…
Get-MsolUser -All -UnlicensedUsersOnly | Remove-MsolUser -Force
To remove all contacts from Office 365…
Get-MsolContact -All | Remove-MsolContact -Force
To remove all groups from Office 365…
Get-MsolGroup -All | Remove-MsolGroup -Force
Lastly, all users that had been removed were purged from Office 365.
- Use PowerShell to Manage Office 365 Users
- Deactivate directory synchronization