Office365 has a relatively simple method for deleting users using the management page, which most people are already familiar with. However, what not everyone knows is that office365 has a recycle bin of sorts, where you can recover deleted users for 30 days after deletion. You can access this by clicking on the “users” tab down the left side then the “deleted” tab at the top of the page. However, there is no easy “empty recycle bin” button here, so this article will explain how to permanently delete office 365 users using powershell.
While this can be a great feature, there are some odd issues that can arise from this. Especially when using directory sync, trying to use the same user principle name can conflict with the deleted item and trying to send emails to the user of the deleted address can sometimes cause routing errors. They are usually unique situations, but none the less I have observed quite a few of them in real life usage.
The solution to this is to clear out the deleted user items permanently. But as usual with office365, this is not a simple web interface button, so we have to go to powershell to get this done. There are two different ways to go here – you can remove a single user at a time if there is one causing a problem but you want to keep the rest. Or, more often than not, it’s easiest to just empty out the entire deleted items box with a single command.
To clear out the entire mailbox at once, use this command in powershell:
Get-MsolUser -ReturnDeletedUsers -All | Remove-MsolUser -RemoveFromRecycleBin -Force
To clear out a single user, first you will need to the user ObjectId. To find it, start with this command:
Command: Get-MsolUser -ReturnDeletedUsers -searchstring *UserUPN here* | fl UserPrincipleName, ObjectID
Example: Get-MsolUser -ReturnDeletedUsers -searchstring User01@abccorp.com | fl UserPrincipleName, ObjectID
This will return to user ObjectID, which you will have to insert into the next command:
Command: Remove-MsolUser -ObjectID *ObjectID here* -RemoveFromRecycleBin -Force
Example: Remove-MsolUser -ObjectID c4d86044-bd23-7218-c226-e556a25a2dac -RemoveFromRecycleBin -Force
No comments yet.