Note: Before proceed, Install and Configure Azure AD PowerShell
Use the following command to connect the Azure Active Directory:
Connect-MsolService
Use the following command to retrieve a list of all deleted users. This command will list all the users that are currently stored in the Recycle Bin folder, and have not deleted permanently because 30 days have not passed since they were moved to this folder.
Get-MsolUser –ReturnDeletedUsers
Once you get the deleted users list, you can decide certain users to delete permanently from this list and you can use the cmdlet Remove-MsolUser to remove a specific deleted user with the parameter –RemoveFromRecycleBin.
Remove-MsolUser -UserPrincipalName [email protected] -RemoveFromRecycleBin -Force
You can remove all the deleted users by fetching all deleted users using Get-MsolUser cmdlet and pipe the output to Remove-MsolUser.
Get-MsolUser -ReturnDeletedUsers | Remove-MsolUser -RemoveFromRecycleBin -Force
You can also filter the deleted users with specific criteria and remove those users permanently.
Get-MsolUser -ReturnDeletedUsers | Where-Object { $_.Department -like '*DevTeam*'} | Remove-MsolUser -RemoveFromRecycleBin -Force