Office 365 Active Directory provides the option to recover office 365 deleted user account.
Each of “deleted user account” will be saved in the Active Directory Recycle bin for 30 days.
When we delete a user account, the operation described as “Soft Delete” because the user account not deleted completely.
Management tasks relating to soft delete are:
- Recover Deleted User account.
- Delete (remove) Deleted user account – delete a user object from the Active Directory Recycle bin (describes as Hard Delete). This option is suitable for scenarios in which the deleted user account “Blocks” creation of new user account with an identical display name or UPN.
In the article, we review the management of the deleted account by using PowerShell commands.
Article Table of content | Click to Expand
PowerShell | Help & additional information
Running PowerShell commands in Office 365 based environment
To be able to run the PowerShell commands specified in the current article, you will need to create a remote PowerShell with Azure Active Directory or Exchange Online. In case that you need help with the process of creating a Remote PowerShell session, you can use the links on the bottom of the Article.
Restore Deleted Office 365 User account
Restore Deleted Office 365 User account
PowerShell command syntax
1 | Restore-MsolUser -UserPrincipalName <Deleted Office 365 User UPN name> |
PowerShell command Example
1 | Restore-MsolUser -UserPrincipalName John@o365info.com |
Restore ALL Deleted Office 365 User accounts (BULK Mode)
PowerShell command Example
1 2 3 4 5 6 | $AllDeletedUsers = Get-MsolUser -ReturnDeletedUsers ForEach ($DELLUser in $AllDeletedUsers) { Restore-MsolUser -UserPrincipalName $DELLUser.UserPrincipalName } |
Restore Deleted Office 365 User account and use Auto Reconcile Proxy Conflicts
PowerShell command syntax
1 | Restore-MsolUser -UserPrincipalName <Deleted Office 365 User UPN name> -AutoReconcileProxyConflicts -NewUserPrincipalName <NEW User UPN> |
PowerShell command Example
1 | Restore-MsolUser -UserPrincipalName John@o365info.com -AutoReconcileProxyConflicts -NewUserPrincipalName JohnNEW@o365info.com |
Display information about Office 365 Deleted user accounts
Display information about Specific Office 365 deleted User account
PowerShell command syntax
1 | Get-MsolUser –ReturnDeletedUsers –SearchString <Deleted Office 365 User UPN name> | Format-list UserPrincipalName,ObjectID |
PowerShell command Example
1 | Get-MsolUser –ReturnDeletedUsers –SearchString John@o365info.com| Format-list UserPrincipalName,ObjectID |
Display a list of ALL Office 365 deleted user accounts
PowerShell command Example
1 | Get-MsolUser -ReturnDeletedUsers | Format-list UserPrincipalName,ObjectID |
Delete (Remove) User account from the Recycle bin
Delete (Remove) deleted user account from the Recycle bin (Hard delete)
PowerShell command syntax
1 | Remove-MsolUser -UserPrincipalName <Deleted Office 365 User UPN name> -RemoveFromRecycleBin –Force |
PowerShell command Example
1 | Remove-MsolUser -UserPrincipalName John@o365info.com -RemoveFromRecycleBin –Force |
Delete (Remove) ALL deleted user accountS from the Recycle bin BULK MODE (Hard delete)
PowerShell command Example
1 2 3 4 5 | $AllDeletedUsers = Get-MsolUser -ReturnDeletedUsers ForEach ($DELLUser in $AllDeletedUsers) { Remove-MsolUser -UserPrincipalName $DELLUser.UserPrincipalName -RemoveFromRecycleBin –Force } |
Export information about Deleted Office 365 User accounts
Export information about Deleted Office 365 User accounts to CSV file
PowerShell command syntax
1 | Get-MsolUser -ReturnDeletedUsers | Export-CSV <Path + File name> –NoTypeInformation -Encoding utf8 |
PowerShell command Example
1 | Get-MsolUser -ReturnDeletedUsers | Export-CSV c:\temp\"Deleted Office 365 User accounts.CSV" –NoTypeInformation -Encoding utf8 |
Getting started with Office 365 PowerShell
Get more information about the Naming Conventions that are used in the PowerShell articles – Help and additional information – o365info.com PowerShell articles
To get more information about the required remote PowerShell commands that you need to use for connecting to Exchange Online, read the following article:
Connect to Exchange Online by using Remote PowerShell
To get more information about the required software component + the remote PowerShell commands that you need to use for connecting Azure Active Directory, read the following article: Part 2: Connect to Office 365 by using Remote PowerShell
If you are new in the PowerShell world, you can read more information about how to start working with PowerShell in Office 365 based environment in the following article series: Getting started with Office 365 PowerShell – Part 1, Part 2, Part 3.
In case that you need more information about how to use the o365info PowerShell scripts that I add to the PowerShell articles, you can read the article – How to run and use o365info PowerShell menu script
It is important for us to know your opinion on this article


I tried to run the above command for empty the recycle bin where I have a deleted user,but I get
The term ‘-RemoveFromRecycleBin’ is not recognized as the name of a cmdlet, function, script file, or operable program. Check the spelling of the name, or if a path was included..
Can you help,because I imported all the modules for office 365 and this command is not available?
Update your powershell module: http://onlinehelp.microsoft.com/Office365-enterprises/ff652560.aspx#BKMK_DownloadTheMOSIdentityFederationTool
Hard delete should only be used as a very last resort when no other option is available. Once deleted in this manner there is NO opportunity for restoring this user or any of the data associated with that user.
A deleted user should NEVER block creation of a new user, although in some cases it may appear that way because the new user creation results in attempting to restore a delete user – but that the restore has a conflict. Conflicts should only be surfaced on a restore operation.
When connected to exchange online i would use this when purging all user from recycle” bin Get-MsolUser -ReturnDeletedUsers | Remove-MsolUser -RemoveFromRecycleBin -force”