Manage Office 365 Recycle bin by using PowerShell | Office 365 5/5 (2) 4 min read

In the current article, we will review how to use PowerShell commands for managing the recovery of user’s accounts in Office 365 environment.

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:

  1. Recover Deleted User account.
  2. 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.

PowerShell | Help & additional information

In case that you are a novice in the PowerShell environment, you can use the following link to get more information about the “first steps” such as: downloading the required PowerShell
software components, how to use the PowerShell console, running a PowerShell script, etc.

Read more
Link Table

PowerShell Naming Conventions & general information

If you want to get more information about the Naming Conventions that we use for this article and get some general tips about: how to work with the PowerShell, read the article: Help and additional information – o365info.com PowerShell articles

Create remote PowerShell session

Before we can use the required PowerShell commands, we need to download and install the Office 365 cmdlets + create remote PowerShell session to Office 365 or Exchange Online. If you need more information about how to create a remote PowerShell session read the following articles: Part 2: Connect to Office 365 by using Remote PowerShell and Part 3: Connect to Exchange Online by using Remote PowerShell

How to use a PowerShell script

Most of the PowerShell articles include a PowerShell script that simplifies the use of the PowerShell commands. If you want to get more information about: How to use a PowerShell script, read the article: Connect to Office 365 and Exchange Online using a script

PowerShell command and Script languish in more details

If you are new to the PowerShell world, you can read more information about PowerShell in Office 365 environment in the article: The Power of PowerShell


1. Restore Deleted User account

1.1 – Restore Deleted User account by using the User UPN

PowerShell command Syntax

PowerShell command Example

1.2 – Restore Deleted User account by using the User GUID

PowerShell command Syntax

PowerShell command Example


2. Display information

2.1 – Display a list of ALL deleted User accounts

PowerShell command Syntax

2.1 – Display information about Specific deleted User account

PowerShell command Syntax

PowerShell command Example


3. Delete (Remove) User account from the Recycle bin

3.1 – Delete (Remove) Specific user account from the Recycle bin

PowerShell command Syntax

PowerShell command Example

3.2 – Delete (Remove) ALL user account from the Recycle bin (Bulk Mode)

PowerShell command Syntax

4. Download Restore Deleted User account PowerShell menu script


For your convenience, I have “Wrapped” all the PowerShell commands that were reviewed in a PowerShell Script named:
Deleted_objects.zip
You are welcome to download the script and use it.

download-button-02.png

PowerShell command syntax – Office 365 | Article series index

Now it’s Your Turn!
It is important for us to know your opinion on this article


Print Friendly

Related Post

Please rate this

Eyal Doron on EmailEyal Doron on FacebookEyal Doron on GoogleEyal Doron on LinkedinEyal Doron on PinterestEyal Doron on RssEyal Doron on TwitterEyal Doron on WordpressEyal Doron on Youtube
Eyal Doron
Share your knowledge.
It’s a way to achieve immortality.
Dalai Lama

4 Responses to “Manage Office 365 Recycle bin by using PowerShell | Office 365”

  1. 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?

  2. 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.

Leave a Reply

Your email address will not be published. Required fields are marked *