Azure AD Connect Sync Filtering
Wer nicht alle seine AD-Objekte über den Azure AD Connect Sync in die Cloud synchronisieren möchte, hat dazu mehrere Optionen. Die einfachste Option ist es, Objekte durch OUs zu trennen (z.B. Administratoren) und diese OUs in der AAD Connect GUI vom Sync auszunehmen.
Ist das nicht möglich oder reicht dies nicht aus, so lassen sich durch Regeln im AAD Synchronization Rules Editor Filter-Regeln ganz individuell bauen. Dabei besteht die Filterung aus (mindestens) zwei Regeln:
- Die erste Regel definiert, anhand welcher Filter die AD Objekte für den Sync ausgewählt werden.
- Die zweite Regel definiert, was mit dem Rest passiert (Catch-All Regel)
Dabei muss die erste Regel eine höhere Priorität (= niedrigere Precedence-Zahl) haben als die zweite Regel. Natürlich können vor der Catch-All Regel weitere Filter Regeln definiert sein, z.B. wenn es mehrere Kriterien für die Filterung gibt. Wichtig ist einfach nur, dass es abschließend eine Catch-All Regel gibt.
Filterung anhand des UserPrincipalNames (UPN)
Eine gängige Unterscheidung von Usern ist der UPN Suffix. So werden häufig externe Mitarbeiter/Dienstleister daran unterschieden.
Als Beispiel sieht in diesem Beitrag das Szenario wie folgt aus:
Domain Name = domain.com
UPN Suffix für interne Mitarbeiter = „internal.domain.com“
UPN Suffix für externe Mitarbeiter/Dienstleister = „external.domain.com“.
Im folgenden Beispiel möchte ich nur interne Mitarbeiter in die Microsoft Cloud synchronisieren und filtere dies eben anhand des UPN-Suffixes. Wie oben beschrieben besteht der Filter aus 2 Regeln. Im Vorfeld müssen wir noch die Connector GUID ermitteln:
Import-Module ADSync # Connector / Connector GUID ermitteln für den OnPrem-Domain Connector & UPN-Suffix definieren $Connector = (Get-ADSyncConnector | Where-Object {$_.Type -eq "AD"}) $UPNSuffix = "@internal.domain.com" # Filter Rule Users New-ADSyncRule ` -Name 'In from AD - User Sync By UPN Suffix = internal.domain.com' ` -Description 'Sync all Users with UPN Suffix = internal.domain.com' ` -Direction 'Inbound' ` -Precedence 11 ` -SourceObjectType 'user' ` -TargetObjectType 'person' ` -Connector $Connector.Identifier.Guid ` -LinkType 'Join' ` -SoftDeleteExpiryInterval 0 ` -ImmutableTag '' ` -OutVariable syncRule Add-ADSyncAttributeFlowMapping ` -SynchronizationRule $syncRule[0] ` -Source @('false') ` -Destination 'cloudFiltered' ` -FlowType 'Constant' ` -ValueMergeType 'Update' ` -OutVariable syncRule New-Object ` -TypeName 'Microsoft.IdentityManagement.PowerShell.ObjectModel.ScopeCondition' ` -ArgumentList 'userPrincipalName',$UPNSuffix,'ENDSWITH' ` -OutVariable condition0 Add-ADSyncScopeConditionGroup ` -SynchronizationRule $syncRule[0] ` -ScopeConditions @($condition0[0]) ` -OutVariable syncRule Add-ADSyncRule ` -SynchronizationRule $syncRule[0] # Catch All Rule Users New-ADSyncRule ` -Name 'In from AD - User Catch-All Filter' ` -Description 'Filterobject for remaining users' ` -Direction 'Inbound' ` -Precedence 21 ` -SourceObjectType 'user' ` -TargetObjectType 'person' ` -Connector $Connector.Identifier.Guid ` -LinkType 'Join' ` -SoftDeleteExpiryInterval 0 ` -ImmutableTag '' ` -OutVariable syncRule Add-ADSyncAttributeFlowMapping ` -SynchronizationRule $syncRule[0] ` -Source @('true') ` -Destination 'cloudFiltered' ` -FlowType 'Constant' ` -ValueMergeType 'Update' ` -OutVariable syncRule Add-ADSyncRule ` -SynchronizationRule $syncRule[0]
Filterung anhand des Wertes in einem Extension Attribute
Möchte man nicht nur User-, sondern auch/oder Group-, Contact & Computer-Objekte filtern, funktioniert die Filterung anhand des UPNs nicht, da Gruppen, Kontakte und Computer keinen UPN haben. Hier muss ein anderes Attribut herhalten. Oftmals verwendet man daher auch Extension Attribute, da dieses in allen Objekt-Typen existiert.
In den folgenden Beispielen möchte ich alle 4 o.g. Objekttypen synchronisieren, deren ExtensionAttribute1
den Wert AADSync
enthält.
Import-Module ADSync # Connector / Connector GUID ermitteln für den OnPrem-Domain Connector $Connector = (Get-ADSyncConnector | Where-Object {$_.Type -eq "AD"}) # Filter Rule Users New-ADSyncRule ` -Name 'In from AD - User Sync By ExtensionAttribute1 = AADSync' ` -Description 'Sync all Users with ExtensionAttribute1 = AADSync' ` -Direction 'Inbound' ` -Precedence 11 ` -SourceObjectType 'user' ` -TargetObjectType 'person' ` -Connector $Connector.Identifier.Guid ` -LinkType 'Join' ` -SoftDeleteExpiryInterval 0 ` -ImmutableTag '' ` -OutVariable syncRule Add-ADSyncAttributeFlowMapping ` -SynchronizationRule $syncRule[0] ` -Source @('false') ` -Destination 'cloudFiltered' ` -FlowType 'Constant' ` -ValueMergeType 'Update' ` -OutVariable syncRule New-Object ` -TypeName 'Microsoft.IdentityManagement.PowerShell.ObjectModel.ScopeCondition' ` -ArgumentList 'extensionAttribute1','AADSync','EQUAL' ` -OutVariable condition0 Add-ADSyncScopeConditionGroup ` -SynchronizationRule $syncRule[0] ` -ScopeConditions @($condition0[0]) ` -OutVariable syncRule Add-ADSyncRule ` -SynchronizationRule $syncRule[0] # Catch All Rule Users New-ADSyncRule ` -Name 'In from AD - User Catch-All Filter' ` -Description 'Filterobject for remaining users' ` -Direction 'Inbound' ` -Precedence 21 ` -SourceObjectType 'user' ` -TargetObjectType 'person' ` -Connector $Connector.Identifier.Guid ` -LinkType 'Join' ` -SoftDeleteExpiryInterval 0 ` -ImmutableTag '' ` -OutVariable syncRule Add-ADSyncAttributeFlowMapping ` -SynchronizationRule $syncRule[0] ` -Source @('true') ` -Destination 'cloudFiltered' ` -FlowType 'Constant' ` -ValueMergeType 'Update' ` -OutVariable syncRule Add-ADSyncRule ` -SynchronizationRule $syncRule[0] # Filter Rule Contacts New-ADSyncRule ` -Name 'In from AD - Contact Sync By ExtensionAttribute1 = AADSync' ` -Description 'Sync all Contacts with ExtensionAttribute1 = AADSync' ` -Direction 'Inbound' ` -Precedence 12 ` -SourceObjectType 'contact' ` -TargetObjectType 'person' ` -Connector $Connector.Identifier.Guid ` -LinkType 'Join' ` -SoftDeleteExpiryInterval 0 ` -ImmutableTag '' ` -OutVariable syncRule Add-ADSyncAttributeFlowMapping ` -SynchronizationRule $syncRule[0] ` -Source @('false') ` -Destination 'cloudFiltered' ` -FlowType 'Constant' ` -ValueMergeType 'Update' ` -OutVariable syncRule New-Object ` -TypeName 'Microsoft.IdentityManagement.PowerShell.ObjectModel.ScopeCondition' ` -ArgumentList 'extensionAttribute1','AADSync','EQUAL' ` -OutVariable condition0 Add-ADSyncScopeConditionGroup ` -SynchronizationRule $syncRule[0] ` -ScopeConditions @($condition0[0]) ` -OutVariable syncRule Add-ADSyncRule ` -SynchronizationRule $syncRule[0] # Catch All Rule Contacts New-ADSyncRule ` -Name 'In from AD - Contact Catch-All Filter' ` -Description 'Filterobject for remaining contacts' ` -Direction 'Inbound' ` -Precedence 22 ` -SourceObjectType 'contact' ` -TargetObjectType 'person' ` -Connector $Connector.Identifier.Guid ` -LinkType 'Join' ` -SoftDeleteExpiryInterval 0 ` -ImmutableTag '' ` -OutVariable syncRule Add-ADSyncAttributeFlowMapping ` -SynchronizationRule $syncRule[0] ` -Source @('true') ` -Destination 'cloudFiltered' ` -FlowType 'Constant' ` -ValueMergeType 'Update' ` -OutVariable syncRule Add-ADSyncRule ` -SynchronizationRule $syncRule[0] # Filter Rule Groups New-ADSyncRule ` -Name 'In from AD - Group Sync By ExtensionAttribute1 = AADSync' ` -Description 'Sync all Groups with ExtensionAttribute1 = AADSync' ` -Direction 'Inbound' ` -Precedence 13 ` -SourceObjectType 'group' ` -TargetObjectType 'group' ` -Connector $Connector.Identifier.Guid ` -LinkType 'Join' ` -SoftDeleteExpiryInterval 0 ` -ImmutableTag '' ` -OutVariable syncRule Add-ADSyncAttributeFlowMapping ` -SynchronizationRule $syncRule[0] ` -Source @('false') ` -Destination 'cloudFiltered' ` -FlowType 'Constant' ` -ValueMergeType 'Update' ` -OutVariable syncRule New-Object ` -TypeName 'Microsoft.IdentityManagement.PowerShell.ObjectModel.ScopeCondition' ` -ArgumentList 'extensionAttribute1','AADSync','EQUAL' ` -OutVariable condition0 Add-ADSyncScopeConditionGroup ` -SynchronizationRule $syncRule[0] ` -ScopeConditions @($condition0[0]) ` -OutVariable syncRule Add-ADSyncRule ` -SynchronizationRule $syncRule[0] # Catch All Rule Groups New-ADSyncRule ` -Name 'In from AD - Group Catch-All Filter' ` -Description 'Filterobject for remaining groups' ` -Direction 'Inbound' ` -Precedence 23 ` -SourceObjectType 'group' ` -TargetObjectType 'group' ` -Connector $Connector.Identifier.Guid ` -LinkType 'Join' ` -SoftDeleteExpiryInterval 0 ` -ImmutableTag '' ` -OutVariable syncRule Add-ADSyncAttributeFlowMapping ` -SynchronizationRule $syncRule[0] ` -Source @('true') ` -Destination 'cloudFiltered' ` -FlowType 'Constant' ` -ValueMergeType 'Update' ` -OutVariable syncRule Add-ADSyncRule ` -SynchronizationRule $syncRule[0] # Filter Rule Computers New-ADSyncRule ` -Name 'In from AD - Computer Sync By ExtensionAttribute1 = AADSync' ` -Description 'Sync all Computers with ExtensionAttribute1 = AADSync' ` -Direction 'Inbound' ` -Precedence 14 ` -SourceObjectType 'computer' ` -TargetObjectType 'device' ` -Connector $Connector.Identifier.Guid ` -LinkType 'Join' ` -SoftDeleteExpiryInterval 0 ` -ImmutableTag '' ` -Disabled ` -OutVariable syncRule Add-ADSyncAttributeFlowMapping ` -SynchronizationRule $syncRule[0] ` -Source @('false') ` -Destination 'cloudFiltered' ` -FlowType 'Constant' ` -ValueMergeType 'Update' ` -OutVariable syncRule New-Object ` -TypeName 'Microsoft.IdentityManagement.PowerShell.ObjectModel.ScopeCondition' ` -ArgumentList 'extensionAttribute1','AADSync','EQUAL' ` -OutVariable condition0 Add-ADSyncScopeConditionGroup ` -SynchronizationRule $syncRule[0] ` -ScopeConditions @($condition0[0]) ` -OutVariable syncRule Add-ADSyncRule ` -SynchronizationRule $syncRule[0] # Catch All Rule Computers New-ADSyncRule ` -Name 'In from AD - Computer Catch-All Filter' ` -Description 'Filterobject for remaining computers' ` -Direction 'Inbound' ` -Precedence 24 ` -SourceObjectType 'computer' ` -TargetObjectType 'device' ` -Connector $Connector.Identifier.Guid ` -LinkType 'Join' ` -SoftDeleteExpiryInterval 0 ` -ImmutableTag '' ` -Disabled ` -OutVariable syncRule Add-ADSyncAttributeFlowMapping ` -SynchronizationRule $syncRule[0] ` -Source @('true') ` -Destination 'cloudFiltered' ` -FlowType 'Constant' ` -ValueMergeType 'Update' ` -OutVariable syncRule Add-ADSyncRule ` -SynchronizationRule $syncRule[0]
Quellen:
https://www.sidekicktech.com/field-notes/upn-suffix-filtering-ad-connect/