As many of you have knowledge, I am studying for my MS-202 Exam. And, part of the knowledge needed is to be able to migrate mailboxes between on premises and Exchange Online through PowerShell. Here are the steps for the scenario to move a mailbox from on premises to O365:
1. Connect to Exchange Online via PowerShell
If you have read my previous post: Connect to All PowerShell Modules in O365 with one script
You should have all the settings needed to connect your PowerShell to O365. Note in this scenario, that all these cmdlets will be run from O365 PowerShell and will be monitored from O365 by either PowerShell or the Exchange Admin Center. You will not be able to monitor the moves from On-Premises.
2. Provide your on premises Migration Administrator credentials as a variable for your cmdlet.
1 | $OnPremCred = Get-Credential -Message "Enter the On Premises Exchange Migration Admin account creds" |
3. Move a single mailbox.
In your hybrid configuration you should be doing directory sync with O365/Azure and the accounts should be available in the cloud showing that they are synced with AD. This also assumes that you have your MRS Proxy endpoint enabled, which can be done by the HCW. Also, make sure you have your licensing available for your mailboxes. From my knowledge, you can assign your license to the account in the cloud before moving, especially if you have a particular license that you need to assign the account. Other than that, moving the mailbox will assign an existing license that is available that includes an Exchange Online mailbox feature when the mailbox is moved.
Now we initiate the move with the cmdlet. Similar to what you would do in the GUI, this simple mailbox move cmdlet initiates the move request. It has most of the same parameters as a local move request including BadItemLimit, LargeItemLimit, AcceptLargeDataLoss, etc…
Use the following LINK for documentation on the New-MoveRequest cmdlet.
1 2 3 4 5 6 7 8 | #Set the identity of the mailbox being moved $user = Read-Host "Enter the alias or E-Mail Address of the user being migrated: " #Next Run the cmdlet for the New Mailbox Move Request New-MoveRequest -Identity $user -remote -RemoteHostName (hybridURL) -TargetDeliveryDomain companyname.mail.onmicrosoft.com -RemoteCredential $OnPremCred -AcceptLargeDataLoss -BadItemLimit 500 -LargeItemLimit 100 -BatchName "$user Mailbox Move to O365" #Get the status of the mailbox move to completion Get-MoveRequest | ? {$_.alias -eq "$user"} | Get-MoveRequestStatistics | fl |
Now with all migration projects, we expect to have to move multiple mailboxes in a single batch. The following will show the process for moving mailboxes in bulk from on premises to O365:
1. Connect to Exchange Online via PowerShell
If you have read my previous post: Connect to All PowerShell Modules in O365 with one script
You should have all the settings needed to connect your PowerShell to O365. Note in this scenario, that all these cmdlets will be run from O365 PowerShell and will be monitored from O365 by either PowerShell or the Exchange Admin Center. You will not be able to monitor the moves from On-Premises.
2. Provide your on premises Migration Administrator credentials as a variable for your cmdlet.
1 | $OnPremCred = Get-Credential -Message "Enter the On Premises Exchange Migration Admin account creds" |
3. Move multiple mailboxes in a single batch.
In your hybrid configuration you should be doing directory sync with O365/Azure and the accounts should be available in the cloud showing that they are synced with AD. This also assumes that you have your MRS Proxy endpoint enabled, which can be done by the HCW. Also, make sure you have your licensing available for your mailboxes. From my knowledge, you can assign your license to the account in the cloud before moving, especially if you have a particular license that you need to assign the account. Other than that, moving the mailbox will assign an existing license that is available that includes an Exchange Online mailbox feature when the mailbox is moved.
This time you want to create a CSV file using the alias or emailaddress as your header and then list the appropriate value for all the users in your batch group. Save the file locally as MigrationBatch01.csv or a name of your choice.
Next you initiate the mailbox moves. When specifying the mailbox identity in the cmdlet, use the respective header in your variable declaration (either $user.EMailAddress OR $user.Alias)
Use the following LINK for documentation on the New-MoveRequest cmdlet.
1 2 3 4 5 6 7 8 | #Import the CSV into the variable state $mailboxes = Import-CSV C:\Migration\MigrationBatch01.csv #Next Run the cmdlet for the New Mailbox Move Request to move each mailbox foreach ($user in $mailboxes) { New-MoveRequest -Identity $user.EMailAddress -remote -RemoteHostName (hybridURL) -TargetDeliveryDomain companyname.mail.onmicrosoft.com -RemoteCredential $OnPremCred -AcceptLargeDataLoss -BadItemLimit 500 -LargeItemLimit 100 -BatchName "Migration Batch 01 Moves to O365" } #Get the status of the mailbox moves in the batch to completion Get-MoveRequest | ? {$_.batchname -like "Migration Batch 01 Moves to O365"} | Get-MoveRequestStatistics | ft -a -wr |
GOOD LUCK WITH YOUR MIGRATIONS!
HAPPY TROUBLESHOOTING!
References:
Moving Individual Mailboxes to O365
Move Mailboxes in Bulk to O365
PowerShell Mailbox Migration to O365
Connect to all PowerShell Modules in O365 with one script
New-MoveRequest Microsoft Document
You writing:
-RemoteHostName (hybridURL)
How to find the HybridURL ?
The Hybrid URL is the URL that was created for your on premises server connection from M365 when configuring the HCW. It is usually the address that your OWA will be addressed to. It also can be one you created but will have a certificate Subject Name that will allow for SSL communications.
been exchange admin for 18 years and I used your script to batch move mailboxes. thanks for this and keep at it!
Can anyone remotely assist me in doing this I tried some other migration routes but failed with invalid certificates
Hello Wondet,
If you have a hybrid setup, then you should have valid certificates enabled and working as the hybrid wizard would not work otherwise and you would not be able to migrate any mailboxes via hybrid. You must have valid certificates for M365 to be able to connect to your server and validate the transfer to the cloud.
Hey Lance this is mega working and just wanted to say thanks, well with this moves it quickly gets in to the user@domain.com -TargetDatabase “DB1” -Priority emergency : ) kind of situation and the very working suggestions worked like a charm and always like to find good articles like this one, very much appreciated, best regards from Ljubljana Nejc