The following PowerShell script helped me and the IT team initiate mailbox migrations from Exchange to Office 365 Exchange Online. I had a couple of challenges to resolve before the script worked in our environment. We used a proxy server, so I needed to pass Proxy.Credentials to use PowerShell through it. Using the migration endpoint in our Exchange environment was another challenge because not all team members were domain admins.
The New-MigrationBatch cmdlet initiates the migration of an on-premises mailbox. The migration can then be completed with Complete-MigrationBatch. The example includes both automatic and manual completion, so choose the method you want to use before running the script. It saved the team a lot of clicking.
#Define user for the migration$upnuser="[email protected]"#Define admin email$emailadmins="[email protected]"#Create and define CSV file as input for New-MigrationBatch$csvfile='.\ExchangeOnlineOnboarding.csv'if(Test-Path$csvfile){Remove-Item$csvfile}Add-Content-Path.\ExchangeOnlineOnboarding.csv-Value'EmailAddress,MailboxType'Add-Content-Path.\ExchangeOnlineOnboarding.csv-Value"$upnuser,"#Set proxy authentication if filtering like McAfee Web Gateway is being used$Wcl=new-objectSystem.Net.WebClient$Wcl.Headers.Add(“user-agent”,“PowerShellScript”)$Wcl.Proxy.Credentials=[System.Net.CredentialCache]::DefaultNetworkCredentials$UserCredential=Get-Credential-UserName$emailadmins-Message"Enter admin credentials"$proxysettings=New-PSSessionOption-ProxyAccessTypeIEConfig$Session=New-PSSession-ConfigurationNameMicrosoft.Exchange-ConnectionUrihttps://outlook.office365.com/powershell-liveid/-Credential$UserCredential-AuthenticationBasic-AllowRedirection-SessionOption$proxysettingsImport-PSSession$Session-DisableNameChecking#This migration batch will Autostart and Autocomplete for 100%. When completed the user will be migrated to Exchange OnlineNew-MigrationBatch-Name$upnuser-SourceEndpointmigration.networknet.nl-CSVData([System.IO.File]::ReadAllBytes("$csvfile"))-AutoStart-BadItemLimit"1000"-TargetDeliveryDomainnetworknet.mail.onmicrosoft.com-AutoComplete-NotificationEmails$emailadmins#This migration batch will Autostart and sync for 95%. You will need to run the Complete-Migration step to finish the final 5%New-MigrationBatch-Name$upnuser-SourceEndpointmigration.networknet.nl-CSVData([System.IO.File]::ReadAllBytes("$csvfile"))-AutoStart-BadItemLimit"1000"-TargetDeliveryDomainnetworknet.mail.onmicrosoft.com-NotificationEmails$emailadminsGet-MigrationBatch-Identity$upnuser|Format-ListComplete-MigrationBatch-Identity$upnuser#Check the migration reportGet-MigrationUserStatistics-Identity$upnuser-IncludeReport|FL *Skip*,Error,Report