O365 – Check Sync batch

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.

connect-msolservice -credential $cred
$O365Session = New-PSSession -ConfigurationName Microsoft.Exchange -ConnectionUri https://ps.outlook.com/powershell -Credential $cred -Authentication Basic -AllowRedirection
Import-PSSession $O365Session


$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"}


    $MailContent+="$Identity `n"
    $MailContent+="Error : $ErrorSummary `n `n"
    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 !

Leave a Reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.

How to whitelist website on AdBlocker?

How to whitelist website on AdBlocker?

  1. 1 Click on the AdBlock Plus icon on the top right corner of your browser
  2. 2 Click on "Enabled on this site" from the AdBlock Plus option
  3. 3 Refresh the page and start browsing the site