Creating a user in Azure active directory is quite easy and what about if you don’t want that user in your Azure Active Directory anymore and want to delete that user? Here in this Azure article, we will learn the steps to delete a user in Azure Active Directory from Azure Portal and using PowerShell.
Table of Contents
How to delete a user in Azure Active Directory
Follow the below steps to remove a user in Azure Active Directory using Azure Portal.
- Log in to the Azure Portal.
- Search for Azure Active Directory and click on the search result Azure Active Directory.
Alternatively, click on the “Show portal menu” button from the top left corner –> Select Azure Active Directory.
3. Click on the Users option from the left navigation on the Azure Active Directory page.
4. Now, on the right side, you will see the list of users present on your Azure Active Directory. Select the user you want to delete —> Click on the Delete button as highlighted below.
5. Click on the Ok button to confirm the deletion process on the next pop-up and you are done.
Bulk user deletion in Azure Active Directory
If you want to delete more than one user at once, then you can do that using the below instructions.
- Select the users you want to delete on the Azure Active Directory page.
- Select the Bulk delete option from the Bulk operations drop-down menu.
3. Click on the Download button to download the CSV template where you need to specify the user name.
4. Open the CSV file and enter the User principal name of each user you wish to delete.
FYI, the user’s principal name is in the second column. Click on the copy button next to the user’s principal name to copy to the CSV file.
Don’t remove anything from the CSV file. Keep the default entries as it is and just enter the user principal name of each user next to the default entries as shown below. After entering the user principal name for each user you wish to delete, Save the CSV file in your local PC.
5. Click on the Bulk operations drop-down menu and select the Bulk delete option again.
On the Bulk delete users pop-up,
- Click on the Select a file button and upload the CSV file that you save in step 4.
- For the option “Are you sure you want to perform the delete operation?”, Type Yes.
It will validate the entries. if there is any issue, it will just show the issue details, and in case there is no issue, it will just show you the file uploaded successfully message, Finally, click on the Submit button.
Now, I got the successful message on the Bulk operation.
Now, to cross-check, you can able to see here, that I am left with one user and the other two users got deleted successfully.
How to delete a user in Azure Active Directory using PowerShell
Well, we can also use Azure PowerShell cmdlet to delete a user in Azure Active Directory.
We can use the Remove-MsolUser Azure PowerShell cmdlet to delete a user in Azure Active Directory within a span of seconds. Note that this removes the user including the licenses and other related data.
You can use the below script to delete the user.
Remove-MsolUser -UserPrincipalName "Your User Principal Name "
Example: Let’s consider an example, I have a user in my Azure Active Directory with the user principal name “firstname.lastname@example.org”. You can just execute the below script to delete the specific user.
Remove-MsolUser -UserPrincipalName "email@example.com"
After the execution of the above script, I got a confirmation pop-up –> Just clicked on the Yes button for confirming the deletion process.
Ohh, I got the below error
“Remove-MsolUser : You must call the Connect-MsolService cmdlet before calling any other cmdlets.”
The complete error message was
Remove-MsolUser : You must call the Connect-MsolService cmdlet before calling any other cmdlets. At line:1 char:1 + Remove-MsolUser -UserPrincipalName "firstname.lastname@example.org ... + ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + CategoryInfo : OperationStopped: (:) [Remove-MsolUser], MicrosoftOnlin eException + FullyQualifiedErrorId : Microsoft.Online.Administration.Automation.MicrosoftOnl ineException,Microsoft.Online.Administration.Automation.RemoveUser
You can see the error message here.
This error message is because, we have not established any connection with the Azure AD so the process is, that we should establish a connection with the Azure Active Directory with the help of the Connect-MsolService cmdlet, and then you can able to delete the user from the Azure Active Directory using the above PowerShell script.
So to solve the error “You must call the Connect-MsolService cmdlet before calling any other cmdlets”, first run the Connect-MsolService Azure PowerShell cmdlet, then you can run the other script.
Run the script like below
Connect-MsolService Remove-MsolUser -UserPrincipalName "email@example.com"
After executing the above script, you will be redirected to enter your credentials and then it will delete the user with in a span of seconds.
If, you don’t want the confirmation pop-up and want to delete the user directly. Then you can use the below script.
Connect-MsolService Remove-MsolUser -UserPrincipalName "firstname.lastname@example.org" -Force
How to permanently delete user from Azure active directory
Once, you delete the user, you can find the user in Azure Active Directory till 30 days. Once you delete the user, after 30 days it will get deleted permanently but if you want to permanently delete the user from the Azure Active Directory immediately then you can just follow the below quick information.
- On the Deleted users (preview) page, select the users you want to delete permanently –> then click on the Delete permanently button.
2. Before clicking on the Ok button, read the instruction properly that says “All data for these users will be irrevocably deleted. Are you sure you want to continue?”. Click on the Ok button to delete the users Permanently.
You may also like following the below articles
- How to create service principal in Azure
- How to create and add members to Azure Active Directory Group
- Azure active directory premium features
- Azure Active Directory Module for Windows Powershell
- What is Azure Active Directory B2B collaboration (Azure AD B2B)
- How to Create Azure Free Account (Step by Step tutorial)
Well, we discussed multiple approaches to delete a user in Azure Active Directory from Azure Portal and using PowerShell. Hope it helps and thanks for reading this article.