You might have run into this issue where you need to delete a bunch of users from Azure. I’ve recently had to do this, and found that through the web application/gui you can only delete one user at a time. I had to delete over 5000 users and 6000 groups in order to migrate Azure Active Directories (story for another blog). It’s important to note that this could likely be related to Office 365 as well since we know that
You can do this through PowerShell, but it’s not straight forward.
There are some requirements you will need to manage this.
- .Net 4.5.2
- Microsoft Online Services Sign-In Assistant
- Wndows Azure Active Directory Module for Windows PowerShell
First Step: Sign on to Azure via PowerShell
For this step you will need to use a Global Administrator account.
- Start PowerShell
- Store your Azure/Office 365 Global Administrator credentials
$credentials = get-credential
- Connect to MSOL (Microsoft Online) Azure using your credentials
connect-msolservice -credential $credentials
To ensure you are connected to Azure, you can check your users using the cmdlet, get-msoluser the result should display your users.
Getting your users
Ok, we’ve now connected to Azure and showed you how to ensure you are connected to Azure. Now to gather a list of users and see how we can go about deleting them. For our purposes we want to delete the 3 dummy user accounts I’ve created.
The first cmdlet we will use will be a combination of getting all of our users and exporting them to a CSV file which can be opened in Excel. The cmdlet is
get-msoluser -all | export-csv c:\allusers.csv
You will now open the file. If you are deleting all of your users, make sure you at least leave behind the global administrator account. For our purposes we are deleting the user1, user2 and user3 accounts, so we will delete all other accounts from this file.
Make sure you save the file. Now we will import the file and tell Azure to delete the users that are contained in the file. You won’t see a status and if it completes it will just move back to a prompt.
import-csv c:\allusers.csv | remove-msoluser -force
If you run get-msoluser you’ll notice the accounts you requested to be deleted are now gone.
If you need to remove groups, the same logic and command structure remains. I won’t go over it in great detail but the cmdlets are
- Get-MsolGroup –All | Export-CSV C:\Groups.csv
- Delete Groups you might want to keep
- Import-CSV C:\Groups.csv | Remove-MsOlGroup –Force
This is the best way I’ve found to manage multiple users, I’ve recently used this method during a large migration (5000 users, 6000 groups). The only thing I would tell you is to be patient, there are no status bars and deleting that many users can take awhile.