ADSync Powershell

Die ersten Versionen des DirSync hatten noch eine EXE zur Steuerung des Verzeichnisabgleichs, die auch per Windows Taskplaner aufgerufen wurde. Mit dem Release von AADConnect wurde auch ein PowerShell Modul "ADSync" installiert, welches bei Windows 2012 auch automatisch mit geladen wird.

Befehle des Modul ADSync

Über "Get-Command" kann schon sehr einfach ermittelt werden, welche neuen Commandlets das Modul bereit stellt. Es ist schön zu sehen, dass sich das Team an die PowerShell-Schreibweisen "Verb-PrefixBefehl" orientiert.

Microsoft erweiterte die Powershell fast mit jeder neuen Version. Die Liste dürfte also schon wieder veraltet sein.

PS C:\> Get-Command -Module adsync

CommandType     Name                                               ModuleName
-----------     ----                                               ----------
Cmdlet          Add-ADSyncAADServiceAccount                        adsync
Cmdlet          Add-ADSyncAttributeFlowMapping                     adsync
Cmdlet          Add-ADSyncConnector                                adsync
Cmdlet          Add-ADSyncConnectorAnchorConstructionSettings      adsync
Cmdlet          Add-ADSyncConnectorAttributeInclusion              adsync
Cmdlet          Add-ADSyncConnectorHierarchyProvisioningMapping    adsync
Cmdlet          Add-ADSyncConnectorObjectInclusion                 adsync
Cmdlet          Add-ADSyncGlobalSettingsParameter                  adsync
Cmdlet          Add-ADSyncJoinConditionGroup                       adsync
Cmdlet          Add-ADSyncRule                                     adsync
Cmdlet          Add-ADSyncRunProfile                               adsync
Cmdlet          Add-ADSyncRunStep                                  adsync
Cmdlet          Add-ADSyncScopeConditionGroup                      adsync
Cmdlet          Disable-ADSyncConnectorPartition                   adsync
Cmdlet          Disable-ADSyncConnectorPartitionHierarchy          adsync
Cmdlet          Disable-ADSyncExportDeletionThreshold              adsync
Cmdlet          Enable-ADSyncConnectorPartition                    adsync
Cmdlet          Enable-ADSyncConnectorPartitionHierarchy           adsync
Cmdlet          Enable-ADSyncExportDeletionThreshold               adsync
Cmdlet          Get-ADSyncAADCompanyFeature                        adsync
Cmdlet          Get-ADSyncAADPasswordResetConfiguration            adsync
Cmdlet          Get-ADSyncAADPasswordSyncConfiguration             adsync
Cmdlet          Get-ADSyncAutoUpgrade                              adsync
Cmdlet          Get-ADSyncConnector                                adsync
Cmdlet          Get-ADSyncConnectorHierarchyProvisioningDNCompo... adsync
Cmdlet          Get-ADSyncConnectorHierarchyProvisioningMapping    adsync
Cmdlet          Get-ADSyncConnectorHierarchyProvisioningObjectC... adsync
Cmdlet          Get-ADSyncConnectorParameter                       adsync
Cmdlet          Get-ADSyncConnectorPartition                       adsync
Cmdlet          Get-ADSyncConnectorPartitionHierarchy              adsync
Cmdlet          Get-ADSyncConnectorTypes                           adsync
Cmdlet          Get-ADSyncExportDeletionThreshold                  adsync
Cmdlet          Get-ADSyncGlobalSettings                           adsync
Cmdlet          Get-ADSyncGlobalSettingsParameter                  adsync
Cmdlet          Get-ADSyncRule                                     adsync
Cmdlet          Get-ADSyncRunProfile                               adsync
Cmdlet          Get-ADSyncScheduler                                adsync
Cmdlet          Get-ADSyncSchema                                   adsync
Cmdlet          Get-ADSyncServerConfiguration                      adsync
Cmdlet          New-ADSyncConnector                                adsync
Cmdlet          New-ADSyncJoinCondition                            adsync
Cmdlet          New-ADSyncRule                                     adsync
Cmdlet          New-ADSyncRunProfile                               adsync
Cmdlet          New-ADSyncScopeCondition                           adsync
Cmdlet          Remove-ADSyncAADPasswordResetConfiguration         adsync
Cmdlet          Remove-ADSyncAADPasswordSyncConfiguration          adsync
Cmdlet          Remove-ADSyncAADServiceAccount                     adsync
Cmdlet          Remove-ADSyncAttributeFlowMapping                  adsync
Cmdlet          Remove-ADSyncConnector                             adsync
Cmdlet          Remove-ADSyncConnectorAnchorConstructionSettings   adsync
Cmdlet          Remove-ADSyncConnectorAttributeInclusion           adsync
Cmdlet          Remove-ADSyncConnectorHierarchyProvisioningMapping adsync
Cmdlet          Remove-ADSyncConnectorObjectInclusion              adsync
Cmdlet          Remove-ADSyncGlobalSettingsParameter               adsync
Cmdlet          Remove-ADSyncJoinConditionGroup                    adsync
Cmdlet          Remove-ADSyncRule                                  adsync
Cmdlet          Remove-ADSyncRunProfile                            adsync
Cmdlet          Remove-ADSyncRunStep                               adsync
Cmdlet          Remove-ADSyncScopeConditionGroup                   adsync
Cmdlet          Search-ADSyncDirectoryObjects                      adsync
Cmdlet          Set-ADSyncAADCompanyFeature                        adsync
Cmdlet          Set-ADSyncAADPasswordResetConfiguration            adsync
Cmdlet          Set-ADSyncAADPasswordSyncConfiguration             adsync
Cmdlet          Set-ADSyncAADPasswordSyncState                     adsync
Cmdlet          Set-ADSyncAutoUpgrade                              adsync
Cmdlet          Set-ADSyncClientVersion                            adsync
Cmdlet          Set-ADSyncConnectorParameter                       adsync
Cmdlet          Set-ADSyncGlobalSettings                           adsync
Cmdlet          Set-ADSyncScheduler                                adsync
Cmdlet          Set-ADSyncSchema                                   adsync
Cmdlet          Set-ADSyncServerConfiguration                      adsync
Cmdlet          Set-MIISADMAConfiguration                          adsync
Cmdlet          Start-ADSyncAADPasswordResetEndpoint               adsync
Cmdlet          Start-ADSyncPurgeRunHistory                        adsync
Cmdlet          Start-ADSyncSyncCycle                              adsync
Cmdlet          Stop-ADSyncAADPasswordResetEndpoint                adsync
Cmdlet          Stop-ADSyncSyncCycle                               adsync
Cmdlet          Test-AdSyncUserHasPermissions                      adsync
Cmdlet          Update-ADSyncConnectorPartition                    adsync
Cmdlet          Update-ADSyncConnectorSchema                       adsync
Cmdlet          Update-ADSyncDirectoryObject                       adsync
Cmdlet          Update-ADSyncDRSCertificates                       adsync

Replikation per Powershell

Interessant ist hier erst mal die Abfrage der aktuellen Replikationszeiten mit:

PS C:\> Get-ADSyncScheduler

AllowedSyncCycleInterval            : 00:30:00
CurrentlyEffectiveSyncCycleInterval : 00:30:00
CustomizedSyncCycleInterval         :
NextSyncCyclePolicyType             : Delta
NextSyncCycleStartTimeInUTC         : 10.03.2016 22:56:02
PurgeRunHistoryInterval             : 7.00:00:00
SyncCycleEnabled                    : True
MaintenanceEnabled                  : True
StagingModeEnabled                  : False

Replikation manuell starten

Die frühere EXE-Datei wurde nun auch durch ein Powershell-Commandlet ersetzt.

Start-ADSyncSyncCycle

Allerdings wartet das Commandlet nicht auf die "Rückkehr" oder die Fertigstellung und gibt auch keinen Ergebniscode aus. Es ist also wirklich nur ein "Trigger". Insofern sollten Sie weiterhin auf das ADSync Monitoring bauen.

Sonstige Commandlets

All die anderen Commandlets haben ich selbst noch nie benutzen müssen. Sicher habe ich bislang schon ein paar "GET-ADSync*"-Commandlets ausprobiert und zu sehen, was sie zurück liefern. Aber im Allgemeinen macht das Setup für den ADSync schon eine gute Arbeit und mit dem Rule Editor können die meisten Aktionen auch fehlerfrei durchgeführt werden.

ADSyncTools "ADSyncTools.psm1"

Neben dem eigentlichen ADSync-Module zur Verwaltung des Service gibt es noch eine Toolbox, die ein paar Aufgaben einfacher machen. Es sind einfach eine Menge von PowerShell Commandlets, deren Namen schon selbst die Funktion beschreiben

Das Modul wird automatische mit ADSync installiert.

Metaverse und ConnectorSpace

Wenn Sie nicht nur die ADSync Konfiguration betrachten wollen, können sie mit PowerShell auch einen Blick in den ConnectorSpace und mit etwas Hilfe auch in das Metaverse werfen. Microsoft erweitert die PowerShell, auch wenn im Jan 2021 noch Lücken bestehen.

Das Commandlet "Get-ADSyncCSObject" war noch nicht dokumentiert und es lieferte die Informationen über ein Objekte, welches man aber per GUID angeben musste. Eine Liste aller Objekte hat das Commandlet zu dem Zeitpunkt noch nicht geliefert. Vielleicht kommt das noch. Auch fehlt z.B. ein "Get-ADSyncMVObject", um Informationen aus dem Metaverse zu generieren.

Bis dahin bleibt nur die Abfrage per WMI, SQL oder andere Helfer.

ADSync Powershell Remote

Über "Invoke-Command" oder "Enter-PSSession" können Sie auch sehr einfach aus der Ferne auf einem anderen Server verschiedene PowerShell-Aktionen ausführen. Mit der ADSync-PowerShell ist das leider nicht ganz so einfach. Ich bekomme immer den folgenden Fehler:

$sessions = New-PSSession -ComputerName ADSYNC1 -credential (get-credential)
Invoke-Command -Session $session -ScriptBlock {Get-ADSyncCSObject -ConnectorName msxfaq.net -StartIndex 1 -MaxResultCount 10}

“Get-ADSyncCSObject: There was no endpoint listening at net.pipe://localhost/ADSyncManagement 
that could accept the message. This is often caused by an incorrect address or SOAP action. 
See InnerException, if present, for more details.”

Selbst wenn ich mich interaktiv verbinde:

Enter-PSSession <servername> -Credential (Get-Credential)
Get-ADSyncCSObject -ConnectorName msxfaq.net -StartIndex 1 -MaxResultCount 10


“Get-ADSyncCSObject: There was no endpoint listening at net.pipe://localhost/ADSyncManagement 
that could accept the message. This is often caused by an incorrect address or SOAP action. 
See InnerException, if present, for more details.”

Leider sind die Commandlets in den DLLs verbuddelt und nicht als PS1-Code einfach lesbar. Ich kann nur vermuten, dass die Commandlets per SQL-API (OLEDB o.ä.) auf die Datenbank zugreifen und die Daten auslesen. Die Fehlermeldung deutet aber nicht darauf hin, dass es ein Authentifizierungsfehler wäre sondern der Endpunkt nicht erreichbar ist. Auf dem Server lokal funktionieren die Skripte problemlos

Weitere Links