Refer to the steps below on how to Move Mailbox to Office 365 with PowerShell
- Prepare a csv file
EmailAddress
[email protected]
[email protected]
The header for this column must be named EmailAddress
- Assign Office 365 License to all users listed in the CSV file
#Assign License
$Users = Import-Csv "C:\Temp\MailboxToMigrate.csv"
$AccountSKU = Get-MsolAccountSku | ? AccountSkuID -like "*ENTERPRISEPACK"
foreach ($User in $Users) {
if (Get-MsolUser -UserPrincipalName $User.UPN) {
Set-MsolUser -UserPrincipalName $User.UPN -UsageLocation MY
Set-MsolUserLicense -UserPrincipalName $User.UPN -AddLicenses $AccountSKU.AccountSkuId
Write-Host -ForegroundColor Green $User.UPN" had been licensed successfully"
}
}
- Define the Name of the Migration Batch, and the Migration Endpoint & target Delivery Domain
$Name = "Batch1-UAT56"
$SourceEndpoint = Get-MigrationEndpoint
#The target Delivery Domain is <tenantname>.mail.onmicrosoft.com
$TargetDeliveryDomain = "M365x333981.mail.onmicrosoft.com"
- Create a migration batch to migrate users listed in CSV file to Office 365
New-MigrationBatch -Name $Name -BadItemLimit 100 -SourceEndpoint $SourceEndpoint.Identity -AutoComplete -CSVData ([System.IO.File]::ReadAllBytes("C:\Temp\temp.csv")) `
-NotificationEmails "[email protected]" -TargetDeliveryDomain $TargetDeliveryDomain
Identity Status Type TotalCount
-------- ------ ---- ----------
Batch1-UAT56 Stopped ExchangeRemoteMove 2
- Start the Migration Batch
Start-MigrationBatch $Name
- Monitor the Migration Batch with Get-MigrationUser & Get-MigrationUserStatistics
Get-MigrationUser
Identity Batch Status LastSyncTime
-------- ----- ------ ------------
[email protected] PS1 Failed
[email protected] UAT3 Completed 26/11/2018 5:41:02 AM
[email protected] Batch1-UAT56 Syncing
[email protected] Batch1-UAT56 Syncing
#Detail Monitoring
$User = "[email protected]"
Get-MigrationUserStatistics -Identity $User | Select MailboxEmailAddress, Status, TotalItemsInSourceMailboxCount, SyncedItemCount, EstimatedTotalTransferSize, BytesTransferred
MailboxEmailAddress : [email protected]
Status : Syncing
TotalItemsInSourceMailboxCount :
SyncedItemCount : 0
EstimatedTotalTransferSize :
BytesTransferred :
- Force the completion of mailbox when it is stucked in SYNCED
#Force Complete for Mailbox shown in SYNCED
$mailbox="[email protected]"
Set-MoveRequest -Identity $mailbox -CompleteAfter (Get-Date)
Resume-MoveRequest -Identity $mailbox
- User can login to https://portal.office365.com to access thier email once the migration batch is completed successfully
Reference
1. https://docs.microsoft.com/en-us/powershell/module/exchange/move-and-migration/new-migrationbatch?view=exchange-ps