Remove Deleted Users from Office 365 Permanently Using PowerShell
Unable to remove deleted users from Office 365 permanently? You can not remove a user from deleted users in the Office 365 Admin Center. You need to run the PowerShell command or you can use the Microsoft Entra Admin Center for the same. In this article, we have described the step-by-step procedure for the same, just go through it and you will find your answer.
When you delete an Office 365 user, they are moved to the recycle bin for 30 days. These deleted users stay in the recycle bin for a retention period of 30 days set by Azure AD. In case the deletion was unintentional, then you can easily restore the deleted Office 365 user from the recycle bin during this retention period. However, after the retention period expires, the contacts cannot be restored anyhow.
In case you have deleted the contacts intentionally and want to delete them permanently by removing them from the recycle bin as well, you can do so with the help of Powershell.
Why Do You Need to Remove Deleted Users from Office 365 Permanently?
Consider a situation where you delete an Office 365 user, due to some issue in the display name of the contact. However, the user whose contact has been deleted needs to use the same UPN or SMTP address after removing the issue in the display name. Since the default retention period is 30 days, you will have to wait for 30 days, before you can use the same UPN for the user after making changes.
In such an instance, permanent deletion of contact from the Active Directory recycle bin is the only way, with the help of which, a user can create a new contact with the same UPN or SMPT address after making the required changes.
- Wrong provisioning of an Office 365 user account.
- Preventing a soft-match through Azure AD Connect when the UPN or primary SMTP address is the same.
- An Office 365 user mailbox with an active hold is to be set to inactive (ex – for exiting employees).
How to Find Deleted Users from Microsoft Office 365?
Step 1. Open your web browser and, sign in to the Microsoft 365 admin center by browsing to admin.microsoft.com. Now enter your admin username and password to sign in.
Step 2. After successful login, navigate to the Users option in the menu on the left-hand side. Click on Users to expand the options.
Step 3. Navigate to the Deleted users section, you can find it under the Users tab in the drop-down menu. Click on Deleted users to view the list of users who have been deleted from your organization’s Microsoft 365 account.
Step 4. Here you can find a list of all the users who have recently deleted, scroll through the list to find the specific user you’re looking for.
How to Permanently Delete Users in Office 365 Using Microsoft Entra Admin Center
Note: To use this approach, you must have an Azure subscription.
Step 1. Navigate to https://entra.microsoft.com/ to access the Microsoft Entra admin center. Use valid admin credentials to log in.
Step 2. From the left pane, you can find the Identity tab. Expand it by clicking on it. You can see a few options in the drop-down menu.
Step 3. Navigate to Users and expand it. There you can find the Deleted users option.
Step 4. Here you will find the list of all the recently deleted users from Microsoft 365.
Step 5. Select and enable the checkbox for all the required users that you want to permanently delete. Then click on the Delete Permanently button.
Pre-Requisites
To proceed with deleting the Office 365 contacts permanently, you need to download and install Azure Active Directory Powershell.
Procedure to Hard Delete Users from Office 365 with PowerShell
Follow the below-mentioned steps for permanently deleting users from Office 365 accounts:
# Connect to Azure Active Directory Connect-MsolService # Retrieve a list of deleted users $deletedUsers = Get-MsolUser -ReturnDeletedUsers # Check if there are any deleted users if ($deletedUsers.Count -gt 0) { Write-Host "Found $($deletedUsers.Count) deleted users." # Iterate through each deleted user foreach ($user in $deletedUsers) { Write-Host "Removing user $($user.UserPrincipalName) permanently..." # Remove the user permanently Remove-MsolUser -UserPrincipalName $user.UserPrincipalName -RemoveFromRecycleBin -Force } Write-Host "All deleted users have been permanently removed." } else {
Write-Host “No deleted users found.”
}
Save this script with a .ps1 extension (e.g., remove_deleted_users.ps1`). Then, execute the script in PowerShell. Make sure you have the necessary permissions to perform these actions.
Before deleting a user permanently, you should back up that Office 365 Mailbox locally. Moreover, you can easily download Office 365 emails to the desktop using the SysTools Office 365 Backup Tool.
PowerShell Command to Remove Bulk Deleted Users from Office 365 Permanently
Using this command you can retrieve up to 25 deleted users and then permanently delete them from the recycle bin in Office 365.
PS C:\Scripts> Get-MsolUser –MaxResults 25 -ReturnDeletedUsers | Remove-MsolUser –RemoveFromRecycleBin -Force
Note: The MaxResults parameter used in the above command is a variable and hence can be changed depending on the number of contacts that must be deleted. The higher the number of contacts, the more time it will take to delete them.
Conclusion
With the help of the PowerShell scripts and Microsoft Entra Admin Center mentioned above, you can easily remove deleted users from Office 365 accounts permanently. This will help you in deleting the users rather than waiting for 30 days to get them deleted automatically.