How to remove duplicate mailbox in Office 365

Sometimes things happen. Migration failed, interns assigning a license to a user when their mailbox is on premise, or some other kind of administrative mistake. Now you realize you have a mailbox on premise and a mailbox in O365. In order to fix the problem, you have to remove one of the accounts. The easiest fix is to remove the cloud account and migrate the on premise account. The reason you want to keep the on premise account is mainly for successful authentication, redirects, and mailflow. Below are the steps to accomplish the task of successfully removing and resyncing the user’s account. This process will save the current mailbox data in a soft deleted state, removed the MSOL account in O365, resync the AD account on prem to O365 and re-create the mailbox.

You know you are running into this issue if you run Get-mailbox in Exchange Powershell on-premise, and you run Get-mailbox in Exchange Online Powershell and both outputs are showing a user mailbox.

This is essentially what will need to be done. In Powershell connected to Exchange Online, please run the following steps:
1.Back up SharePoint and OneDrive data! Once the Msol object is deleted, that data may or may not be recoverable. Need to open a case or reach out to the SharePoint Online team to confirm.
2.Check to see if the current mailbox for Steve is on litigation hold. If not, Set the mailbox on litigation hold to save the data. 1. Set-Mailbox [insert alias] -LitigationHoldEnabled $true

3.Verify the litigation hold is in place. *May take up to 60 minutes, but is typically pretty quick. 1. Get-Mailbox [insert alias] | fl *lit*

4.Get more the mailbox information. We will need the GUID for later. 1. Get-Mailbox [inser alias | fl userpprincipalname,guid

5.Get-msol user information of the account that we need to purge. 1. Get-msoluser -userprincipalname [insert upn of user] | fl

6.Delete the old MSOL account information using the objectID from step 4. (Yes, you need to run both cmdlets here) 1. Remove-msoluser -objectid
2.Remove-msoluser -objectid -removefromrecyclebin

7.Verify the user has been deleted. 1. Get-msoluser -objectid -returndeletedusers

8.Run Dirsync. The Old account should be gone from delete items. You may need to run Dirsync twice. Verify that the new account has synced to O365 and is showing “Sync with Active Directory” in the O365 admin portal.
9.Migrate on premise mailbox to EXO.
10.Assign a license to the new mailbox.
11.In Exchange Online Powershell, get the mailbox information for the new mailbox. Copy the GUID. 1. Get-Mailbox [user alias] | fl name,GUID

12.Now merge the data to the new mailbox. 1. New-mailboxrestoreRequest -sourcemailbox [Guid of old mailbox from Step4] -targetmailbox [GUID of new mailbox step 11] -allowLegacyDNMismatch

13.Verify the mailbox restore is in place. 1. Get-mailboxrestorerequest

14.Verify the data is restored and the mailbox is healthy.
15.You can now remove litigation hold for the old mailbox if you chose. If you don’t then the mailbox will just be retained for the length of the specified litigation hold.