
O365 – Check Sync batch
When you are doing a migration from Exchange to O365, there are two ways :
- Direct Migration
- Two step migration (provisioning then migrating)
If you choose the second way, you’ll have to check if all mailboxes are synced and not failed.
That little script let you connect to O365 and then get all “Failed” sync status, grab all information about it and, remove the failed user from your batch, and finally, send you a report by mail.
$cred=get-credential connect-msolservice -credential $cred $O365Session = New-PSSession -ConfigurationName Microsoft.Exchange -ConnectionUri https://ps.outlook.com/powershell -Credential $cred -Authentication Basic -AllowRedirection Import-PSSession $O365Session $datej=get-date $UserFailed=0 $Smtp="mysmtp.mydomain.com" $MailFrom="Migration O365 <no-reply@mydomain.com>" $MailTo="ROUALIN Chris <chris.roualin@mydomain.com>" $MailObject="Migration Status - $datej" $MailContent="Here below is the list of Sync Failed users : `n `n" $MigratioNotSynced=Get-MigrationUser |Where-Object{$_.Status -eq "Failed"} $MigratioNotSynced|Foreach-object{ $Identity=$_.Identity $BatchName=$_.Batch $ErrorSummary=$_.ErrorSummary $MailContent+="$Identity `n" $MailContent+="Error : $ErrorSummary `n `n" $UserFailed+=1 Write-host "Error detected for $Identity - batch $BatchName" Write-host "Error : $ErrorSummary" Remove-MigrationUser $Identity -Confirm:$false } Get-pssession |where-object{$_.ComputerName -eq "ps.outlook.com"}|foreach-object{$sessionid=$_.id; remove-pssession $sessionid} If($UserFailed -gt 0){ Send-MailMessage -from $MailFrom -to $MailTo -Subject $MailObject -Body $MailContent -SmtpServer $smtp }
Sûre you could change the authentication method, replacing the “get-credential” by whatever you want to schedule that script as a task and auto check it !
This is just a quick script to check !