Exporting DirSyncID for import into Office365

During our upgrade process from Live@EDU to Office365, the DirSyncID attribute was not copied between the two systems. This attribute is used by ILM to link the user object in the cloud with the user object in an on-site Active Directory.

In order to easily maintain this link, we used the following Powershell commands to export (just before the upgrade) and then import (before enabling FIM and Federation) afterwards.

Export

Before clicking the “Upgrade” button to upgrade from Live@EDU to Office365, run the following as an admin user connected to your Live@EDU instance:

get-syncmailbox -resultsize unlimited | select userprincipalname,dirsyncid | export-csv dirsyncids.csv

Import

This script is a little more complicated as it handles any errors that may occur as part of the import process (during testing we noticed about 10% of commands failed due to rate-limiting however during the real load they all worked fine…).  Any errors encountered result in the failed line being output to a new CSV which can be re-run through the same script until there are no errors left 🙂

The script is invoked as:

.\script.ps1 [ -file <inputfile> ] [ -errorfile <errorfile> ]

You’ll get a progress bar showing how far through the import you are. You may want to consider splitting up the input file and running a few jobs in parallel to speed up the import process – our run of about 60,000 objects took was going to take about 12 hours.

Script:

param(
[String]$file="dirsyncids.csv",
[String]$errorfile="errors.csv"
)

$errors = @()

write-host Starting up using file=$file errors=$errorfile
$csv = Import-CSV $file
write-host Opened $file with $csv.Length rows
date

$error_count = 0

foreach ($row in $csv) {
    Write-Progress -Activity import -status "Processing $($row.username); $error_count errors" -PercentComplete ($count / ($csv.Length) * 100)
    try {
        $ErrorActionPreference = "Stop"
        set-msoluser -UserPrincipalName $($row.userprincipalname) -ImmutableId $row.dirsyncid
    } catch {
        $error_count = $error_count + 1
        $row | export-csv -Append -path $errorfile
    } finally {
        $ErrorActionPreference = "Continue"
    }
}

Write-Progress -Activity import -Completed
date

Hope that helps!

Leave a Reply