Run AAD Connect Sync & Monitor Status

Depending on the size of an AD environment (and more specifically, the number and location of objects that are in scope to be synced), a delta sync can take anywhere between a couple of seconds and significantly longer.

Checking if a sync currently is running is possible using a couple of methods. When sticking to PowerShell, the following commands can be utilized:

Start-AdSyncSyncCycle: running this command interactively when a sync is running will result in an “in your face” error message similar to the following:

Get-AdSyncScheduler: this command outputs the configuration settings of the sync process and also includes the state, wether or not it is running:

While all of the above are usable, they are not that user friendly, and require a user to retry the command in order to know *when* sync has been completed.

The below PowerShell code (let’s not call it a script, shall we?) does the following things:

  • Checks if a sync process currently is running
  • If not, starts a delta sync
  • Notifies the user / admin when the delta sync is finished
# verify if ADSync module is loaded, and if not, load it.
$module = Get-Module "ADsync"
if ($module -eq $null)
{
Import-Module AdSync
}else
{
    Write-Host "ADSync Module already loaded"
}

# verify if a sync is currently running. If not, start a delta sync
$sync = Get-AdSyncScheduler

if ($sync.SyncCycleInProgress -eq $False)
{
Start-AdSyncSyncCycle -Policytype "Delta" |Out-Null
}

# periodically test if sync is running until it's... not running anymore
do {
    Write-Host "Azure AD Connect Sync Cycle in Progress..." -ForegroundColor "Yellow"
    $sync = Get-AdSyncScheduler
    
} until ($sync.SyncCycleInProgress -eq $False)

Write-Host "Azure AD Connect Sync Cycle is finished." -ForegroundColor "Green"

Jente Paredis

Jente Paredis

I am an experienced architect with a strong focus on Security, Identity & Productivity Solutions . I specialize in Azure AD, M365, and Azure Infrastructure Solutions. Throughout my professional career, I have had the pleasure to work with bright-minded people. I care deeply about both People and Technology.

Contact?

Dat kan vandaag nog!

 

Ik sta voor de combinatie van flexibiliteit en passie.

Hierdoor ben ik vaker dan een gemiddeld bedrijf bereikbaar om te helpen met jouw IT-gerelateerd project, probleem of vraagstuk!

Contact

Waarom jentech?

Expert Consultancy

Met meer dan 15 jaar ervaring in zowel KMO-omgevingen als multinationals, is jentech dé betrouwbare partner voor al jouw IT vraagstukken!

Microsoft Training

Expertise opbouwen, up-to-date houden én delen zit in mijn DNA. Ik hecht dan ook véél belang aan het behalen van relevante Microsoft certificaten.

Samenwerking

Ik ben er rotsvast van overtuid dat de combinatie van mijn expertise en jouw inzichten tot een onklopbare samenwerking leidt!

Visie

Ik wil mensen en organisaties helpen om hun eigen doelstellingen te halen door kwalitatieve IT-oplossingen aan te bieden.