Delete All Deleted Users in Office 365

Do you have a need to delete all deleted users from your Office 365 account before the retention period expires?

Working with Office 365 in a lab scenario (or even in production) you might accumulate a large cache of deleted users.  This list of users could become unsightly and if you are certain they will not need to be restored (like I was), could not to wait for the 30 day retention to lapse.

Here is how we do it…

We will use Windows Azure Active Directory Module for Windows PowerShell (AD Module) to connect to our Office 365 tenant to delete the users.  This PowerShell module (released on 28 Feb 2013) is the newest version and has replaced the MOS Module for Windows PowerShell.  Information on Windows PowerShell can be found here… http://technet.microsoft.com/library/jj151815.aspx.  The new AD Module can be downloaded from here … http://go.microsoft.com/fwlink/p/?linkid=236297.

Open Windows Azure Active Directory Module for Windows PowerShell, then type…

Connect-MsolService

Enter your Office 365 admin credentials when prompted.  Next, enter the following command to remove all deleted users from the Office 365 account…

Get-MsolUser -ReturnDeletedUsers -All | foreach { Remove-MsolUser -ObjectId $_.ObjectId -RemoveFromRecycleBin -Force }

Or, use this simpler command…

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

If you would like to delete deleted users individually, please refer to this link … http://dereksan.blogspot.com/2012/08/permanently-delete-office-365-msoluser.html

Todd (@oddytee)

Originally published on 7 March 2013 at http://oddytee.blogspot.com/2013/03/delete-all-deleted-users-in-office-365.html

 

Reference(s):

Advertisements

One thought on “Delete All Deleted Users in Office 365

  1. Pingback: Remove Users, Contacts and Groups from Office 365 | Cloud Evangelist

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s