In this Azure PowerShell article, we will discuss the syntax and usage of the Remove-MsolUser Azure PowerShell command with an example of how to use this command.
Table of Contents
Remove-MsolUser
This PowerShell command can help you to remove a user from your Azure Active Directory.
Syntax
Below is the syntax of the Remove-MsolUser PowerShell command.
Remove-MsolUser -UserPrincipalName "Your User Principal Name "Let’s see an example of how to use the Remove-MsolUser PowerShell command.
Example
For example, I have a user in my Azure Active Directory with the user principal name “test@fewlines4bijuhotmail.onmicrosoft.com”. You can execute the below script to delete the specific user.
Remove-MsolUser -UserPrincipalName "test@fewlines4bijuhotmail.onmicrosoft.com"After executing the above script, I got a confirmation pop-up –> Just clicked on the Yes button to confirm 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 "test@fewlines4bijuhotmail.onmicro ...
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : OperationStopped: (:) [Remove-MsolUser], MicrosoftOnlin
eException
+ FullyQualifiedErrorId : Microsoft.Online.Administration.Automation.MicrosoftOnl
ineException,Microsoft.Online.Administration.Automation.RemoveUserYou 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. Then, you can 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, and then you can run the other script.
Run the script like below
Connect-MsolService
Remove-MsolUser -UserPrincipalName "test@fewlines4bijuhotmail.onmicrosoft.com"After executing the above script, you will be redirected to enter your credentials. Then, within seconds, the user will be deleted.
Suppose you don’t want the confirmation pop-up and want to delete the user directly. Then, you can use the script below.
Check out Remove-MsolUser not recognized, in case you get the error while executing this command.
Conclusion
You can use the Remove-MsolUser PowerShell command to delete a user from your Azure Active Directory. In this article, we discussed the syntax and usage of the Remove-MsolUser PowerShell command with an example of how to use this command.

I am Rajkishore, and I am a Microsoft Certified IT Consultant. I have over 14 years of experience in Microsoft Azure and AWS, with good experience in Azure Functions, Storage, Virtual Machines, Logic Apps, PowerShell Commands, CLI Commands, Machine Learning, AI, Azure Cognitive Services, DevOps, etc. Not only that, I do have good real-time experience in designing and developing cloud-native data integrations on Azure or AWS, etc. I hope you will learn from these practical Azure tutorials. Read more.
