{"id":2932,"date":"2019-07-11T11:50:43","date_gmt":"2019-07-11T09:50:43","guid":{"rendered":"http:\/\/wordpress.networknet.nl\/?p=2932"},"modified":"2019-07-11T11:50:43","modified_gmt":"2019-07-11T09:50:43","slug":"powershell-new-migrationbatch-for-exchange-online-migration","status":"publish","type":"post","link":"https:\/\/www.networknet.nl\/apps\/wp\/archives\/2932","title":{"rendered":"PowerShell: New-MigrationBatch for Exchange Online migration"},"content":{"rendered":"<p>\n\tThe following <strong>PowerShell<\/strong> script helped myself and the IT team to initiate <strong>migration<\/strong> from Exchange to Office 365 <strong>Exchange Online<\/strong> 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&nbsp;Proxy.Credentials needs to be passed within the&nbsp;environment. Another challenge I&nbsp;had is that to use the migration endpoint on our Exchange environment as not all team members are domain admins.\n<\/p>\n<p>\n\t<strong>New-MigrationBatch<\/strong> commandlet is being used that initiates the migration of an on-premise mailbox and with the&nbsp;<strong>Complete-MigrationBatch <\/strong>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.\n<\/p>\n<pre class=\"brush:powershell\">\r\n#Define user for the migration\r\n$upnuser = &quot;Ivan@networknet.nl&quot;\r\n\r\n#Define admin email\r\n$emailadmins = &quot;admin@networknet.nl&quot;\r\n\r\n#Create and define CSV file as input for New-MigrationBatch\r\n$csvfile = &#39;.\\ExchangeOnlineOnboarding.csv&#39;\r\nif (Test-Path $csvfile) {  Remove-Item $csvfile}\r\nAdd-Content -Path .\\ExchangeOnlineOnboarding.csv  -Value &#39;EmailAddress,MailboxType&#39; \r\nAdd-Content -Path .\\ExchangeOnlineOnboarding.csv  -Value &quot;$upnuser,&quot; \r\n\r\n#Set proxy authentication if filtering like McAfee Web Gateway is being used\r\n$Wcl = new-object System.Net.WebClient\r\n$Wcl.Headers.Add(&ldquo;user-agent&rdquo;, &ldquo;PowerShell Script&rdquo;)\r\n$Wcl.Proxy.Credentials = [System.Net.CredentialCache]::DefaultNetworkCredentials\r\n\r\n$UserCredential = Get-Credential -UserName $emailadmins -Message &quot;Enter admin credentials&quot;\r\n$proxysettings = New-PSSessionOption -ProxyAccessType IEConfig\r\n$Session = New-PSSession -ConfigurationName Microsoft.Exchange -ConnectionUri https:\/\/outlook.office365.com\/powershell-liveid\/ -Credential $UserCredential -Authentication Basic -AllowRedirection -SessionOption $proxysettings\r\nImport-PSSession $Session -DisableNameChecking\r\n\r\n#This migration batch will Autostart and Autocomplete for 100%. When completed the user will be migrated to Exchange Online\r\nNew-MigrationBatch -Name $upnuser -SourceEndpoint migration.networknet.nl -CSVData ([System.IO.File]::ReadAllBytes(&quot;$csvfile&quot;)) -AutoStart -BadItemLimit &quot;1000&quot; -TargetDeliveryDomain networknet.mail.onmicrosoft.com -AutoComplete -NotificationEmails $emailadmins\r\n\r\n#This migration batch will Autostart and sync for 95%. You will need to run the Complete-Migration step to finish the final 5%\r\nNew-MigrationBatch -Name $upnuser -SourceEndpoint migration.networknet.nl -CSVData ([System.IO.File]::ReadAllBytes(&quot;$csvfile&quot;)) -AutoStart -BadItemLimit &quot;1000&quot; -TargetDeliveryDomain networknet.mail.onmicrosoft.com -NotificationEmails $emailadmins\r\nGet-MigrationBatch -Identity $upnuser | Format-List\r\nComplete-MigrationBatch -Identity $upnuser\r\n\r\n#Check the migration report\r\nGet-MigrationUserStatistics -Identity $upnuser -IncludeReport  | FL *Skip*,Error,Report\r\n<\/pre>\n","protected":false},"excerpt":{"rendered":"<p>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&nbsp;Proxy.Credentials needs to be passed within the&nbsp;environment. Another challenge I&nbsp;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&nbsp;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 = &quot;Ivan@networknet.nl&quot; #Define admin email $emailadmins = &quot;admin@networknet.nl&quot; #Create and define CSV file as input for New-MigrationBatch $csvfile = &#39;.\\ExchangeOnlineOnboarding.csv&#39; if (Test-Path $csvfile) { Remove-Item $csvfile} Add-Content -Path .\\ExchangeOnlineOnboarding.csv -Value &#39;EmailAddress,MailboxType&#39; Add-Content -Path .\\ExchangeOnlineOnboarding.csv -Value &quot;$upnuser,&quot; #Set proxy authentication if filtering like McAfee Web Gateway is being used $Wcl = new-object System.Net.WebClient $Wcl.Headers.Add(&ldquo;user-agent&rdquo;, &ldquo;PowerShell Script&rdquo;) $Wcl.Proxy.Credentials = [System.Net.CredentialCache]::DefaultNetworkCredentials $UserCredential = Get-Credential -UserName $emailadmins -Message &quot;Enter admin credentials&quot; $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 [&hellip;]<\/p>\n","protected":false},"author":2,"featured_media":1270,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[594,51,515],"tags":[879,878,851,877,848,42,11,880],"class_list":["post-2932","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-exchange-2010","category-microsoft","category-powershell-microsoft","tag-automation","tag-complete-migrationbatch","tag-exchange-online","tag-new-migrationbatch","tag-office-365","tag-powershell","tag-script","tag-sourceendpoint"],"_links":{"self":[{"href":"https:\/\/www.networknet.nl\/apps\/wp\/wp-json\/wp\/v2\/posts\/2932","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.networknet.nl\/apps\/wp\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.networknet.nl\/apps\/wp\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.networknet.nl\/apps\/wp\/wp-json\/wp\/v2\/users\/2"}],"replies":[{"embeddable":true,"href":"https:\/\/www.networknet.nl\/apps\/wp\/wp-json\/wp\/v2\/comments?post=2932"}],"version-history":[{"count":1,"href":"https:\/\/www.networknet.nl\/apps\/wp\/wp-json\/wp\/v2\/posts\/2932\/revisions"}],"predecessor-version":[{"id":2933,"href":"https:\/\/www.networknet.nl\/apps\/wp\/wp-json\/wp\/v2\/posts\/2932\/revisions\/2933"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/www.networknet.nl\/apps\/wp\/wp-json\/wp\/v2\/media\/1270"}],"wp:attachment":[{"href":"https:\/\/www.networknet.nl\/apps\/wp\/wp-json\/wp\/v2\/media?parent=2932"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.networknet.nl\/apps\/wp\/wp-json\/wp\/v2\/categories?post=2932"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.networknet.nl\/apps\/wp\/wp-json\/wp\/v2\/tags?post=2932"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}