Duplicate Mailboxes in O365 and On-premise Exchange

I recently completed a Hybrid migration from a local Exchange server to the cloud. This was for about 350 mailboxes so we could not just do a cut-over. One of the minor annoying things is that sometimes there was a bug where we would get mailboxes on the Exchange server and a mailbox in O365. What would happen with the mail is that people that were in this predicament would not get mail from either O365 or the Exchange server depending on what mailbox their mail client was synced. An easy way to fix this is to delete the mailbox in O365. The easiest way to do this is to connect through PowerShell.


Step 1:

Log in to your O365 account via powershell with the following script.

  • $cred = Get-Credential
  • $Session = New-PSSession -ConfigurationNameĀ  Microsoft.Exchange -ConnectionUri https://ps.outlook.office365.com/powershell/ -Credential $cred -Authentication Basic -AllowRedirection
  • Import-PSSession $Session

Step 2:

Now you will want to find the Msol (Microsoft Online) user. I like to double check everything before I delete something to make sure that I am not deleting the wrong thing.

  • Get-MsolUser -UserPrincipalName user@example.com

Step 3:

The next command will remove the user from Exchange Online altogether. This means that the user will be completely deleted from O365.

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

Now, after the local environment has synced with the cloud you should be able to migrate the user without much trouble. This article is purely for my knowledge so I don’t have to back to google time and again, because this is something I do rarely. I hope it helps someone else out there as well.

Advertisements

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 )

Google photo

You are commenting using your Google 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 )

Connecting to %s

%d bloggers like this:
search previous next tag category expand menu location phone mail time cart zoom edit close