365-command-logoFor this week’s edition of Justin’s Tech Tip of the week, 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. 

Our 365Command  development team will have the GUI built for this process soon, but in the meantime the cmdlet’s that you need to fix this 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 username@mydomain.com

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

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.

…. And that is Justin’s Tech Tip of the Week.  Thanks again!

To view any of my previous tips, see here:

Shared Mailboxes Part I -What to do if you want or need to convert a full (user) Office 365 mailbox into a Shared Mailbox.

Shared Mailboxes Part II – How do you create a shared mailbox from scratch and then add permissions to them?  

Office 365 Calendar Invites and Meeting Requests

Archive Mailboxes

Mail Retrievals within Office 365

How to use Microsoft Active Directory Synchronization (“MS DirSync”) for Office 365 more effectively

Exchange Hybrid/Coexistence migrations to Office 365

Alleviate local SSL cert pop-ups

Windows XP and Office 365