- Using Azure Active Directory
- Has used AAD Sync to sync on-premise user account and group
- Discovered has accidently sync user account and group to Azure Active Directory but require to remove it.
It’s quite a painful experience to delete each individual user account and group from Azure Management Portal. Wonder why no multiple select option and quite annoying when it asking for confirmation and refresh. But lucky enough got powershell to do the job.
- Install Microsoft Online Services Sign-In Assistant for IT Professionals RTW
- Install Azure Active Directory Module for Windows PowerShell (64-bit version),
After install the pre-requisite, open the Azure Active Directory Module for Windows Powershell.
Connect to Azure Active Directory by entering the Global Administrator account.
$msolcred = get-credential
Export the user account to csv file format
|Get-MsolUser –All | Export-CSV C:\users.csv|
Open the csv file and remove the Microsoft account and Global Administrator account. We just want to remove others account and retain the Global administrator account.
Export the group to csv file format
|Get-MsolGroup –All | Export-CSV C:\Groups.csv|
Final step is start to remove bulk users account and groups
|Import-CSV C:\Users.csv | Remove-MsOlUser –Force|
|Import-CSV C:\Groups.csv | Remove-MsOlGroup –Force|
Deletion process is quite long period if you’ve more than 8000 records.