Powershell : Remotely start a Entra Connect Syncronisation

If you are using Entra Sync (which used to be called AD-Connect) and this is the software responsible for keeping your on-premises domain in sync with Entra.

I would rather remotely manager servers that physically (or virtually) logging into them, so let script the start of one of these sync cycles in Powershell.


If you run the command with no syntax it will initiate a delta sync and that looks like this:

.\EntraSyncRemote.ps1

If you wish to complete a "full" synchronisation then you can specify the -Full command on the end like this:

.\EntraSyncRemote.ps1 -Full

Script : EntraSyncRemote.ps1

param(
    [switch]$Full
)
# Define server name
$ServerName = "<servername>"
try {
    # Create remote script block
    $scriptBlock = {
        Import-Module ADSync
        if ($using:Full) {
            Start-ADSyncSyncCycle -Policy Initial
            Write-Host "Running Initial (Full) sync on $using:ServerName"
        } else {
            Start-ADSyncSyncCycle -Policy Delta
            Write-Host "Running Delta sync on $using:ServerName"
        }
    }
    # Execute remote command
    Invoke-Command -ComputerName $ServerName -ScriptBlock $scriptBlock
}
catch {
    Write-Error "Failed to execute AD sync: $_"
}

Previous Post Next Post

نموذج الاتصال