Forever Immutable – ID gefällig - oder - Dirsync extended

2013-05-07 | Christoph Wilfing

Mir ist das zuletzt was interessantes passiert – es hat ein wenig mit einer Immutable ID zu tun – siehe Wiki.

Also – einfach beschrieben ist eine ImmutableID eindeutig und sollte sich niemals ändern. Das bringt mich auf eine Idee.. wollten sie schon immer mal die Welt aus den Angeln heben und etwas unveränderliches ändern? Jetzt ist die Zeit dafür gekommen.

Ich habe zuletzt bei einem Kunden das Problem bei einer frischen ADFS / DirSync Installation als Basis aber eine bestehende Domain ohne onPremise Exchange aber mit bestehendem W14 O365 Account. Also – der Kunde hat halt bisher an lokalen Domain User gehabt plus eine online Identity die getrennt voneinander zu verwalten war. Was letztendlich etwas lästig aber in kleineren Umgebungen ja nicht so dramatisch ist.

Trotzdem wollte der Kunde auf ADFS inkl. Dirsync umstellen mit dem Problem – wie genau krieg ich Dirsync dazu einen lokalen User auf einen online User zu matchen und nicht sofort alles kaputt zu machen?

Naja – es gibt mal eine offizielle Aussage wie DirSync ein Matching macht wenn man nachträglich synchronisiert.

http://technet.microsoft.com/en-us/library/jj863117.aspx

Matching functionality 1—GUID match logic. When you reactivate directory synchronization, objects in the on-premises Active Directory are matched with objects in the cloud according to previous directory synchronization GUID (objectGUID) on the cloud objects. When such a match is found, the directory synchronization process makes a GUID match and overwrites the target object data in the cloud objects with the data from the corresponding on-premises objects.

Matching functionality 2—SMTP match logic. If directory synchronization does not find a GUID match in the cloud, a process called SMTP match is used. In this process, directory synchronization matches corresponding objects, according to the primary SMTP address. If a target (cloud) object’s primary SMTP address matches a primary SMTP address of an object in the on-premises organization, the data for the on-premises object is used to overwrite the data for the corresponding cloud object.

ABER – ganz wichtig…

http://support.microsoft.com/kb/2641663/en-us

SMTP matching can be used only one time for user accounts that were originally authored by using Office 365 management tools. After that, the Office 365 user account is bound to the on-premises user by an immutable identity value instead of a primary SMTP address. The cloud user’s primary SMTP address can't be updated during the SMTP matching process because the primary SMTP address is the value that is used to link the on-premises user to the cloud user. 

Wie man so schön sagt – da gibts jetzt genau EINEN Versuch – wenn der schief geht – hat ma doppelte Accounts. Blöd eher. Aber – ich wäre nicht ich wenn ma das ned mit ein paar zeilen Powershell wieder lösen könnte Smile Also – Ärmel hochgekrempelt und los gehts.

Step 1:

Durch den fehlgeschlagenen Sync hat man mal einen Account der die Mailbox besitzt und einen Account der gesynct wurde und keine Mailbox besitzt. Meistens leicht zu erkennen am falschen UserPrincipalName.

image

Einen User mit der “original” Domain und einen mit der “@<tenant>.onmicrosoft.com” (hier simuliert).

Jetzt muss man mal den falsch gesyncten User löschen – wir müssen leider auch den gelöschten User aus dem Papierkorb löschen, da ja sonst unser User beim Sync wieder gematched wird. (im Papierkorb)

image

Step 2:

Jetzt müssen wir unserem DirSync beibringen das es unseren User schon gibt. Nachdem wir aber beim ersten Sync nachlässig waren und damit in der DirSync Datenbank bereits ein User existiert der nicht auf den User im Azure Active Directory gematched wurde, müssen wir das halt.. “von Hand” machen.

image

Im DirSync Client (miisclient.exe – zu finden auf dem DirSync Server im Install Verzeichnis “\%programdir%\Microsoft Online Directory Sync\SYNCBUS\Synchronization Service\UIShell\miisclient.exe” einfach alle Accounts auflisten lassen und dann den entsprechendne sourceAnchor beim Searchresult hinzufügen (Rechtsklick | Column Settings). Der SourceAnchor entspricht der ImmutableID des Users den wir versuchen zu synchen. In unserem Online Account ist das aber leider “leer”… na dann.. lasst es uns setzen.

image

Wie man sieht – geht das relativ einfach:

image

Einmal den Sync anstossen im Dirsync und schon wird unser online User mit dem User vom lokalen Directory gematched und überschrieben.

Jetzt kommt die klassische Frage – wenn ich jetzt aber 534 User habe und das ned jedesmal einzeln machen will? Ganz simple Powershell kann ja wie bekanntlich mehr. Einfach die Search im DirSync machen – alles markieren und copy / paste in ein Textfile. rauskommt ungefähr sowas:

DisplayName,UPN,ImmutableID
2013 Test01,2013Test01@2und40.at,m6RSeMTxIEucmy1Z/47Qrg==
2013 Test02,2013Test02@2und40.at,eMxejPXflkSPCnK43ju40Q==
2013 Test03,2013Test03@2und40.at,t+27mdq4fk+Gf/VxddxB4g==
2010 Test01,2010test01@falsch.at,+bWKtuzDCUWFLtXi1gyDDQ==
2010 Test02,2010Test02@2und40.at,B5vVE9Ei40mbpzz9MX114Q==
2010 Test03,2010Test03@2und40.at,IpIqVbuWPUO7msNU+Tiz5g==

Die erste Zeile wird manuell hinzufügt damit wir mit

$UserList = Import-Csv -Delimiter ',' -Path .\userlist.txt

diese Userliste in ein Object Importieren können. Danach ist es relativ simple die entsprechenden User mit der Azure Active Directory Powershell zu matchen, in etwa so:

$UserList | % { Set-MsolUser -UserPrincipalName $_.UPN -ImmutableId$_.ImmutableID }

Also – eigentlich nicht dramatisch oder?

Wie immer gilt – für alle Schäden und kaputte User Accounts, verlorene Mailboxen oder zerstörte DirSync Installation oder sonstige Datenverluste bin ich weder verantwortlich noch verantwortlich zu machen. Jeder ist seines eigen Powershell Master.

LG Christoph

Categories: Cloud, Microsoft, Office365, PowerShell

Source: https://blog.atwork.at/post/Forever-ImmutableID