Knowledge BaseHow do i manage/delete users in Office 365 Recycle Bin
W P Staff asked 7 years ago

How?

1 Answers
W P Staff answered 7 years ago

Manage Office 365 Recycle bin by using PowerShell | Office 365

Manage-Office-365-Recycle-bin-by-using-PowerShell

 
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.

Article Table of content | Click to Expand

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


1. Restore Deleted User account

1.1 – Restore Deleted User account by using the User UPN
PowerShell command Syntax

 
 
 
PowerShell

 

1

Restore-MsolUser –UserPrincipalName <User UPN> -AutoReconcileProxyConflicts -NewUserPrincipalName <User UPN>

PowerShell command Example

 
 
 
PowerShell

 

1

Restore-MsolUser -UserPrincipalName user1@o365info.com -AutoReconcileProxyConflicts -NewUserPrincipalName user1@o365info.com

1.2 – Restore Deleted User account by using the User GUID
PowerShell command Syntax

 
 
 
PowerShell

 

1

Restore-MsolUser –ObjectId <GUID> -AutoReconcileProxyConflicts -NewUserPrincipalName

PowerShell command Example

 
 
 
PowerShell

 

1

Restore-MsolUser -ObjectId b9e82087-ad92-4632-a219-d779c29d2edd -AutoReconcileProxyConFLicts -NewUserPrincipalName user1@o365info.com


2. Display information

2.1 – Display a list of ALL deleted User accounts
PowerShell command Syntax

 
 
 
PowerShell

 

1

Get-MsolUser -ReturnDeletedUsers | FL UserPrincipalName,ObjectID

2.1 – Display information about Specific deleted User account
PowerShell command Syntax

 
 
 
PowerShell

 

1

Get-MsolUser –ReturnDeletedUsers –SearchString <User UPN>| FLUserPrincipalName,ObjectID

PowerShell command Example

 
 
 
PowerShell

 

1

Get-MsolUser –ReturnDeletedUsers –SearchString User1@o365info.com | FLUserPrincipalName,ObjectID


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

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

 
 
 
PowerShell

 

1

Remove-MsolUser -ObjectId <GUID>  -RemoveFromRecycleBin –Force

PowerShell command Example

 
 
 
PowerShell

 

1

Remove-MsolUser -ObjectId b9e82087-ad92-4632-a219-d779c29d2edd -RemoveFromRecycleBin –Force

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

 
 
 
PowerShell

 

1

Get-MsolUser -ReturnDeletedUsers | Remove-MsolUser -RemoveFromRecycleBin –Force