Steps to Remove Azure Active Directory Users and Groups
In this blog, We will show you the Steps to Remove Azure Active Directory Users and Groups using Windows PowerShell.
- Microsoft Azure Subscriptions
- Windows VM
- We have already installed Active Directory Domain named azdomain.local and created three users for the demo purpose.
- Also, we have synchronized the local Active Directory users with Azure AD.
- We can not delete the AD users from the Azure portal. Delete user option will be greyed out.
EXPORTING AZURE AD USERS AND GROUPS
- Open the PowerShell window and connect to the Azure Active Directory using Global administrator account using below command.
- Provide the global admin ID from the pop-up screen and click Next.
- Enter the Password and click Sign in.
- After successful login, export the Azure AD user into a CSV file using the below command.
Get-MsolUser –All | Export-CSV C:\ADusers.csv
- The file ADusers.csv will be available on C: drive.
- Export the Azure AD Groups into a CSV file using the below command.
Get-MsolGroup –All | Export-CSV C:\ADGroups.csv
- Open the ADusers.csv and remove the Global administrator account from the list.
- Save and close the CSV file.
DELETE THE AD USERS AND GROUPS
- From the PowerShell window, execute the below command to delete the AD users.
Import-CSV C:\ADusers.csv | Remove-MsOlUser –Force
- Run the below command to delete the AD Groups.
Import-CSV C:\ADGroups.csv | Remove-MsOlGroup –Force
- Open the Azure portal, and click on the Active Directory users and groups link.
- Click on All users Link. Only the Global administrator account is available on the list.
- There is no groups are available on the list.
Thanks for reading this blog. We hope it was useful for you to know the steps to delete the Azure Active Directory users using Powershell command.