Notice: Due to size constraints and loading performance considerations, scripts referenced in blog posts are not attached directly. To request access, please complete the following form: Script Request Form Note: A Google account is required to access the form.
Disclaimer: I do not accept responsibility for any issues arising from scripts being run without adequate understanding. It is the user's responsibility to review and assess any code before execution. More information

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

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