When it comes to moving emails from one mailbox to another, the first thing that comes to my mind is to use the ugly PST file. Export the emails from one mailbox and then import them into another, via Outlook. Truth be told, while it’s a feasible option, it’s daunting as hell.
A much better option is to use PowerShell and let the server do all the work. And one cmdlet that just does the job is Search-Mailbox.
Here is how it goes.
First of all, connect to Exchange Online.
Connect-ExchangeOnline
An Office 365 login window pops up, sign in with an account that is a member of the Discovery Management role. You can log in as a Global Admin and go to Exchange > Permissions to edit the Discovery Management role.
Then, to move all emails from one mailbox to another,
Search-Mailbox $sourcemailbox -TagertMailbox $targetmailbox -TargetFolderName $targetfoldername
All three parameters are required. Messages will be copied to the target mailbox under the specified folder name. The structure goes like this:
TargetFolderName\Date of the search\Primary Mailbox\Inbox
It works like a charm. However, there is one limitation. It only returns 10,000 results per mailbox. So, for a larger mailbox or a larger amount of messages to move around, use the New-ComplianceSearch instead, which is a lot more complex.
If you want to see how big the mailbox is you are dealing with, use the -EstimateResultOnly switch.
Search-Mailbox $sourcemailbox -EstimateResultOnly
You can also use the -SearchQuery switch to narrow down the messages that you want to migrate, such as subject line, To or From.
Search-Mailbox $sourcemailbox -SearchQuery "Subject: Away Today"
And if you need to do a dry run, use -LogOnly.
Need very detailed log for the operation? -LogLevel Full is your friend.
Lastly, to make this all happen, you need to be part of the Discovery Management role in Office 365.