{"id":45,"date":"2013-04-06T07:09:48","date_gmt":"2013-04-06T07:09:48","guid":{"rendered":"http:\/\/blogs.kent.ac.uk\/unseenit\/?p=45"},"modified":"2013-04-06T07:09:48","modified_gmt":"2013-04-06T07:09:48","slug":"exporting-dirsyncid-for-import-into-office365","status":"publish","type":"post","link":"https:\/\/blogs.kent.ac.uk\/unseenit\/exporting-dirsyncid-for-import-into-office365\/","title":{"rendered":"Exporting DirSyncID for import into Office365"},"content":{"rendered":"<p>During our\u00a0<em>upgrade<\/em> 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\u00a0<em>cloud<\/em> with the user object in an on-site Active Directory.<i><br \/>\n<\/i><\/p>\n<p>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.<\/p>\n<h2>Export<\/h2>\n<p>Before clicking the &#8220;Upgrade&#8221; button to upgrade from Live@EDU to Office365, run the following as an admin user connected to your Live@EDU instance:<\/p>\n<pre>get-syncmailbox -resultsize unlimited | select userprincipalname,dirsyncid | export-csv dirsyncids.csv<\/pre>\n<h2>Import<\/h2>\n<p>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\u00a0<em>real<\/em> load they all worked fine\u2026). \u00a0Any 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 \ud83d\ude42<\/p>\n<p>The script is invoked as:<\/p>\n<pre>.\\script.ps1 [ -file &lt;inputfile&gt; ] [ -errorfile &lt;errorfile&gt; ]<\/pre>\n<p>You&#8217;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 \u2013 our run of about 60,000 objects took was going to take about 12 hours.<\/p>\n<p>Script:<\/p>\n<pre>param(\r\n[String]$file=\"dirsyncids.csv\",\r\n[String]$errorfile=\"errors.csv\"\r\n)\r\n\r\n$errors = @()\r\n\r\nwrite-host Starting up using file=$file errors=$errorfile\r\n$csv = Import-CSV $file\r\nwrite-host Opened $file with $csv.Length rows\r\ndate\r\n\r\n$error_count = 0\r\n\r\nforeach ($row in $csv) {\r\n    Write-Progress -Activity import -status \"Processing $($row.username); $error_count errors\" -PercentComplete ($count \/ ($csv.Length) * 100)\r\n    try {\r\n        $ErrorActionPreference = \"Stop\"\r\n        set-msoluser -UserPrincipalName $($row.userprincipalname) -ImmutableId $row.dirsyncid\r\n    } catch {\r\n        $error_count = $error_count + 1\r\n        $row | export-csv -Append -path $errorfile\r\n    } finally {\r\n        $ErrorActionPreference = \"Continue\"\r\n    }\r\n}\r\n\r\nWrite-Progress -Activity import -Completed\r\ndate<\/pre>\n<p>Hope that helps!<\/p>\n","protected":false},"excerpt":{"rendered":"<p>During our\u00a0upgrade process from Live@EDU to Office365, the DirSyncID attribute was not copied between the two systems. This attribute is used by ILM to link &hellip; <a href=\"https:\/\/blogs.kent.ac.uk\/unseenit\/exporting-dirsyncid-for-import-into-office365\/\">Read&nbsp;more<\/a><\/p>\n","protected":false},"author":13,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":[],"categories":[1],"tags":[862,28920],"_links":{"self":[{"href":"https:\/\/blogs.kent.ac.uk\/unseenit\/wp-json\/wp\/v2\/posts\/45"}],"collection":[{"href":"https:\/\/blogs.kent.ac.uk\/unseenit\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/blogs.kent.ac.uk\/unseenit\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/blogs.kent.ac.uk\/unseenit\/wp-json\/wp\/v2\/users\/13"}],"replies":[{"embeddable":true,"href":"https:\/\/blogs.kent.ac.uk\/unseenit\/wp-json\/wp\/v2\/comments?post=45"}],"version-history":[{"count":1,"href":"https:\/\/blogs.kent.ac.uk\/unseenit\/wp-json\/wp\/v2\/posts\/45\/revisions"}],"predecessor-version":[{"id":46,"href":"https:\/\/blogs.kent.ac.uk\/unseenit\/wp-json\/wp\/v2\/posts\/45\/revisions\/46"}],"wp:attachment":[{"href":"https:\/\/blogs.kent.ac.uk\/unseenit\/wp-json\/wp\/v2\/media?parent=45"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/blogs.kent.ac.uk\/unseenit\/wp-json\/wp\/v2\/categories?post=45"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/blogs.kent.ac.uk\/unseenit\/wp-json\/wp\/v2\/tags?post=45"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}