Skip Navigation LinksRemove-cloud-Mailboxes-and-users

Uninstall the Microsoft Online Services Module for Windows Powershell old version and then, Download the new updated version of the "Windows Azure Active Directory for Windows PowerShell"


 

Download the 32-bit module

Download the 64-bit module


 

If the customer already has it installed uninstall it first then download and install the newest version (this is to obtain the RemoveFromRecycleBin switch not available in previous versions).

 

2. With the new Windows Azure Active Directory for Windows PowerShell run the following command-let:


For specific user:

Get-MsolUser -ReturnDeletedUsers -UserPrincipalName user@domain.com| FT UserP*,ObjectId

 

Get-MsolUser -ReturnDeletedUsers -UserPrincipalName user@domain.com| FL

 

For all deled user:

Get-MsolUser -ReturnDeletedUsers | ft UserP*,ObjectId

3. Based on the output above select the users that need to be permanently removed (no recovery possible) and run the following command-let:

 

Remove-MsolUser -ObjectId abc1234-12abc-123a-ab12-a12b3c4d5f6gah –RemoveFromRecycleBin -Force or not as safe to run but if you want to remove all deleted users simply run:

 

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

 

For all users in the organization, run the command below:

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

 

4. Confirm the deletion and that it was successful by running Get-MsolUser -ReturnDeletedUsers once more and confirm that the issue is resolved. This should work for both DirSync situations and for instances where there is no extra license available until the fix is rolled out to resolve this on the server side.

 

To remove a user that is synchronized with Directory Synchronization, run the command below:

Remove-MsolUser -UserPrincipalName user@example.com -Force

 

To remove a deleted user from deleted user from RecycleBin

Remove-MsolUser -UserPrincipalName user@example.com -RemoveFromRecycleBin -Force

 

To remove Security Groups from MOP, run the command below:

Get-MsolGroup -ALL | Remove-MsolGroup -Force

 

How to remove all Users from O365 Portal for a specific domain:

Get-MsolUser -All -DomainName YourDomain.com |Remove-MsolUser - Force

To search Mailboxes recently deleted or that has Retention/Litigation on hold anebled:

Get-Mailbox -InactiveMailboxOnly -softdeletedmailbox


To permanently delete the affeted mailbox run:

Get-mailbox -softdeletedmailbox AliasHere | remove-mailbox -permanentlyDelete -Force -Confirm:$false

If you receive the error for multiple entries:

The operation couldn't be performed because 'Soft Deleted Objects\<<AffectedMailboxHere>' matches multiple entries.

+ CategoryInfo : NotSpecified: (:) [Remove-Mailbox], ManagementObjectAmbiguousException


 ​ In the scenario where orphan mailboxes can exist, run the commands below to locate the orphan mailboxes:

Get-Mailbox -IncludeInactiveMailbox -SoftDeletedMailbox -ResultSize Unlimited | Where {$_.Identity -Match "Soft Deleted Objects*"} | FT SamAccountName,WindowsEmailAddress


Remove from the duplicate results from the bottom of the list to up of the list using the command:

Get-mailbox -SoftdeletedMailbox SamAccountNameHere | Remove-Mailbox -PermanentlyDelete -Force -Confirm:$false​



For more information:

http://support.microsoft.com/kb/2619308

http://community.office365.com/en-us/forums/150/p/62712/237233.aspx#237233