We will see in this tutorial how to remove a user from your domain Azure Active Dirctory in Powershell.
Before anything, you will need the module MSOL and its Powershell commands to be able to connect to the Azure Active Directory domain and act on items in this area. I will probably return to the installation of the module in a next tutorial, in the meantime feel, free to follow the documentation from Microsoft here https://docs.microsoft.com/en-us/powershell/azure/active-directory/install-msonlinev1?view=azureadps-2.0.
Start a Powershell console and then enter the following command to connect:
A connection prompt appears and simply use a local account “onmicrosoft.com”, or a verified domain account to connect. Of course, the account must have the necessary rights to connect.
Once connected, to remove a user, enter the following command using its “User Principal Name”.
Get-MsolUser - UserPrincipalName email@example.com | Remove-MsolUser
If by chance you are wrong on the command and delete a bad user, don’t worry, the command you just learn does not permanently remove user but put it in the Recycle Bin Azure AD for 30 days before being completely removed.
We will see together in a next tutorial, how to recover a deleted user or how to permanently delete a user without waiting for the deadline of 30 days.