The following PowerShell script helped myself and the IT team to initiate migration from Exchange to Office 365 Exchange Online cloud environment. I had couple of challenges to solve before this script was fully operation and working in the environment I am in. Proxy server is being used and to allow to use PowerShell directly the Proxy.Credentials needs to be passed within the environment. Another challenge I had is that to use the migration endpoint on our Exchange environment as not all team members are domain admins.
New-MigrationBatch commandlet is being used that initiates the migration of an on-premise mailbox and with the Complete-MigrationBatch the migration can be fully completed. Before using the script ensure to uncomment the method you will be using. For me and the team this script was very helpful as lots of clicking was not needed anymore.
#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-object System.Net.WebClient $Wcl.Headers.Add(“user-agent”, “PowerShell Script”) $Wcl.Proxy.Credentials = [System.Net.CredentialCache]::DefaultNetworkCredentials $UserCredential = Get-Credential -UserName $emailadmins -Message "Enter admin credentials" $proxysettings = New-PSSessionOption -ProxyAccessType IEConfig $Session = New-PSSession -ConfigurationName Microsoft.Exchange -ConnectionUri https://outlook.office365.com/powershell-liveid/ -Credential $UserCredential -Authentication Basic -AllowRedirection -SessionOption $proxysettings Import-PSSession $Session -DisableNameChecking #This migration batch will Autostart and Autocomplete for 100%. When completed the user will be migrated to Exchange Online New-MigrationBatch -Name $upnuser -SourceEndpoint migration.networknet.nl -CSVData ([System.IO.File]::ReadAllBytes("$csvfile")) -AutoStart -BadItemLimit "1000" -TargetDeliveryDomain networknet.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 -SourceEndpoint migration.networknet.nl -CSVData ([System.IO.File]::ReadAllBytes("$csvfile")) -AutoStart -BadItemLimit "1000" -TargetDeliveryDomain networknet.mail.onmicrosoft.com -NotificationEmails $emailadmins Get-MigrationBatch -Identity $upnuser | Format-List Complete-MigrationBatch -Identity $upnuser #Check the migration report Get-MigrationUserStatistics -Identity $upnuser -IncludeReport | FL *Skip*,Error,Report
Leave a comment