Purging and Removing Deleted Users and Mailboxes from Office 365


To totally unlock this section you need to Log-in


Login
NOTE: to use the following commands you'll need to install, on a Windows system, Microsoft Online Services Sign-In Assistant 7.0 (Beta) and Windows Azure Active Directory Module for Windows PowerShell package.

Why to force deletion?

In this article we will discuss how to purge/remove deleted users/mailboxes from Office 365 without having to wait for Microsoft’s default 30-day window to ultimately, completely eradicate the account.

This is especially useful if there is a mistake or typo found with a particular user (for example their Display Name) yet they need to use the same UPN for the new and adjusted account.

When you delete the user in question, they will be moved to the “Deleted Users” section within the Office 365 portal.

It is at this point you are at the mercy of waiting that 30 days (1 whole month), for that thing to finally be gotten rid of.

The problem is, if you don’t purge this account, and you attempt to create the new user with the adjusted settings and the same UPN or primary SMTP address, you will get an error citing that there is already an object with this same information, thus the operation cannot be completed.

This is one of those cases, where waiting for the 30-day window for Microsoft to purge your deleted users and mailboxes simply is not sufficient.

To bypass this situation and force the deletion of these users the cmdlet that you need to fix this issue are below:

Purge Deleted Users and Mailboxes from Office 365

Single-User Deletion:

In order to permanently purge a single-user from the “Deleted users” section, execute the following:

Remove-MsolUser –UserPrincipalName [email protected]

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

This will work with BOTH DirSync’d and non-dirsynched (users created directly in the Office 365 tenant).

If you just want to list, to be sure before the deletion, which are the DeletedUsers on Office 365 tenant directly from Powershell you can use just use the following command:

Get-MsolUser -ReturnDeletedUsers

Bulk User Deletion

If you have multiple users that need to be purged, you can then execute the command below:

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

NOTE: the –MaxResults parameter is variable, and you can choose a different number other than 30. This particular command will purge the first 30 deleted users that the command encounters. You can adjust this lower or higher. Keep in mind that the higher that you make the number, the longer it will take to run as it is trying to purge/accumulate a larger number of accounts to purge.

Purge External Contacts:

A similar command can be run to purge deleted contacts as well, in case you need to quickly recreate them

Get-MSOLcontact –SearchString “gary” | FL DisplayName, EmailAddress, ObjectID Remove-MSOLContact –ObjectID “ObjectID”

Where “gary” is part of the Display Name for the contact in question.

1 thought on “Purging and Removing Deleted Users and Mailboxes from Office 365”

  1. Let’s say you’re managing an Office 365 tenant and you’ve “soft-deleted” some users from your cloud Active Directory. Now you’ll have to wait for 30 days before, as policy, Microsoft will remove these users completely from your cloud. How to force this behaviour and delete users without waiting for so many days?

    Discover how reading the following article on HeelpBook:

    Purging and Removing Deleted Users and Mailboxes from Office 365 – http://heelpbook.altervista.org/2014/purging-and-removing-deleted-users-and-mailboxes-from-office-365/ #exchange #howto @heelpbook #office365 #mailbox

Comments are closed.