Merging Two Office 365 Mailboxes

Merging Two Office 365 Mailboxes

There are many reasons why you may want to do this but probably the most likely is the “Leaver” scenario.  A common way of dealing with leavers is to simply convert their Mailbox to a Shared Mailbox and then terminate the user account.  (Sometimes, but not very often these days, it is exported to a PST)

Sometimes I have also seen the New Joiner simply inherit the old mailbox, and have a full end-to-end rename process for the Azure AD Account i.e. UPN, alias, email address etc whilst retaining the leaver information as a proxyAddresses.

At the end of this blog, I am going to include a link to a Microsoft Consultant’s excellent blog and script regarding moving merging specific folders inside the same mailbox or cross mailbox – “Merge mailbox folders using EWS”

Shared Mailbox

The Shared Mailbox can remain as a good resource for checking old email and as an entry in the Global Address List to still receive email.  This Shared Mailbox can be hidden from the GAL and enabled with a permanent autoresponder and a forwarder.  This method does of course mean that anyone wanting access to those old emails needs to be granted Access (usually Full Access) to the mailbox and connect it to their Outlook Profile as a separate mailbox.  That in itself entails a few issues because if it is hidden from the GAL then an end user can’t actually add it in Outlook. In OWA they would need to know how to connect to an additional mailbox. Not massively hard, but another step, nonetheless.  In Outlook additional Mailboxes don’t respect the Outlook slider bar either * (was all or nothing cached) – so a very large secondary mailbox could consume a large OST file on disk.

* Kind of… If you add a mailbox using the additional account method you can use the slider bar, if you just add an Additional mailbox, you will get all the Secondary Mailbox data inside your own OST and it will use your slider settings.

Another way

Another way is to simply merge the leaver mailbox into the new joiner or other mailbox.  Now it used to be that you had to import a PST, but now you can do it right in PowerShell.

Technically the method below is actually all about eDiscovery and can in fact be used to only copy over a subset of documents that match a criterion.

PowerShell script to move/copy emails between Office 365 mailboxes

For executing the following PowerShell scripts, the user must be a member of “Discovery Management” Admin Role Group.

Discovery ManagementAdministrators or users who are members of the Discovery Management role group can perform searches of mailboxes in the Exchange Online organization for data that meets specific criteria and can also configure legal holds on mailboxes.

Note: By default, Search-Mailbox is available only in the Mailbox Search or Mailbox Import Export roles, and these roles aren’t assigned to any role groups. To use this cmdlet, you need to add one or both of the roles to a role group (for example, the Organization Management role group). Only the Mailbox Import Export role gives you access to the DeleteContent parameter. For more information about adding roles to role groups, see the “Add a role to a role group” section in Manage role groups. For example, if you need to use “DeleteContent” switch in “Search-Mailbox” cmdlet for removing the emails from source mailbox after copying to the target mailbox, then assign the “Mailbox Import Export” role to “Discovery Management” Role group.

Search-Mailbox -Identity "" -TargetMailbox "" -TargetFolder "JohnJonesMailbox" -LogLevel Full

The process takes a while to run, and will only process up to 10,000 results. When you run the above CMDLET you will see this warning:

WARNING: The Search-Mailbox cmdlet returns up to 10000 results per mailbox if a search query is specified. To return more than 10000 results, use the New-MailboxSearch cmdlet or the In-Place eDiscovery & Hold console in the Exchange Administration Center.

You can run a test run to see what the total count would be:

search-mailbox -Identity conrad -EstimateResultOnly

search-mailbox -Identity -EstimateResultOnly

WARNING: The Search-Mailbox cmdlet returns up to 10000 results per mailbox if a search query is specified. To return more than 10000 results, use the New-MailboxSearch cmdlet or the In-Place eDiscovery & Hold console in the Exchange Administration Center.

RunspaceId : 7282ac97-81b0-4abe-8a90-5ddfc8f0ff40
Identity : john.jones
TargetMailbox :
Success : True
TargetFolder :
ResultItemsCount : 78100
ResultItemsSize : 7.158 GB (7,685,519,981 bytes)


If you have greater than 10,000 results then you need to use New-MailboxSearch.  These searches will also appear under Compliance Management in the Exchange Admin Centre GUI in Office 365

New-MailboxSearch -Name "John to Jane" -SourceMailboxes -TargetMailbox -LogLevel Full

Now you need to start it:

Get-MailboxSearch "John to Jane" | Start-MailboxSearch

Use the Get-Mailbox Search to check the status

Get-MailboxSearch -Identity "John to Jane" | FL status

Large Items

New-MailboxSearch is actually useful for looking for many things, but larger items is particularly handy:

  • New-MailboxSearch -Name "Conrad Large Items" -SourceMailboxes conrad -SearchQuery ‘size>26214400’ -EstimateOnly
  • Get-MailboxSearch "Conrad Large Items" | Start-MailboxSearch
  • Get-MailboxSearch "Conrad Large Items" | FT name,status,sourcemailboxes,PercentComplete,ResultNumberEstimate,ResultSizeEstimate -AutoSize
Conrad Large ItemsEstimateSucceeded{conrad}10012

PowerShell: Merge mailbox folders using EWS (with throttling support)

A PowerShell script that uses EWS (requires the EWS Managed API) to merge folders within a mailbox.  Can be used for multiple folders, and automated against multiple mailboxes.  It will also copy whole mailboxes from Source to Target.

Microsoft Tech Notes on CMDLETS