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 AAD / MSOL Account, UPN, alias, email address etc whilst retaining the leaver information as a proxyAddress.

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 resource for checking old email and as an entry in the Global Address List to still receive email.  This could 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. If it is hidden from the GAL then an end user can’t actually add it in Outlook and then of course they only have it in Outlook, not on their mobile device. In OWA they would need to know how to connect to an additional mailbox. Not massively hard, but another step, nonetheless. *In Outlook Secondary Mailboxes previously didn’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 Management Administrators 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 "john.jones@contoso.com" -TargetMailbox "jane.smith@contoso.com" -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

PS C:\PSWorkingDirectory> search-mailbox -Identity john.jones@contoso.com -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)

 

New-MailboxSearch

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 john.jones@contoso.com -TargetMailbox jane.smith@contoso.com -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 -Name "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

 

Name Status SourceMailboxes PercentComplete ResultNumberEstimate
Conrad Large Items EstimateSucceeded {conrad} 100 12

 

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

https://code.msdn.microsoft.com/office/PowerShell-Merge-mailbox-e769c529

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

Search-Mailbox

https://docs.microsoft.com/en-us/powershell/module/exchange/mailboxes/search-mailbox?view=exchange-ps

New-MailboxSearch

https://docs.microsoft.com/en-us/powershell/module/exchange/policy-and-compliance-content-search/new-mailboxsearch?view=exchange-ps

 

Conrad Murray

Conrad Murray has been working in IT for over 15 years specializing in the Messaging Arena and in particular IBM Domino and Microsoft Exchange and now of course Office 365. Working with like minded colleagues now specializing in very large scale complex migrations from Lotus Notes and On-Premise Microsoft Exchange to Office 365.

Leave a Reply

Your email address will not be published. Required fields are marked *

Search