When a user is deleted from Office 365 the account is moved into a recycle bin where it is held for 30 days before being purged, this is very useful should users be accidentally deleted and can be easily recovered however this can still cause issues with Azure Active Directory Connect (AADC - used for syncing users from on-premise to Office365) when you have duplicated users/errors when trying to link up accounts for the first time when the first sync may have been done incorrectly, this guide shows you how to permanently delete the problematic deleted item therefore allowing you to redo the AADC sync as if for the first time.

Connect to MSOL

Connect-MsolService

If your execution policy is restricted you will need to run the following command;

Set-ExecutionPolicy RemoteSigned

Enter administrator credentials for your Office365 environment when prompted

 

Verify the user exists in the 30 day deleted state

Get-MsolUser -ReturnDeletedUsers

Tip: If the command above does not work, run Get-MsolUser to ensure you are connected which will return a list of users in the directory

Delete the user using the following command (Please verify UserPrincipalName is correct before running this command)

Remove-MsolUser -UserPrincipalName <This email address is being protected from spambots. You need JavaScript enabled to view it.> -RemoveFromRecycleBin

Confirm
Continue with this operation?
[Y] Yes  [N] No  [S] Suspend  [?] Help (default is "Y"):Y

The account should now be removed

Verify the user has now been removed using

Get-MsolUser -ReturnDeletedUsers