What It Does
This script changes one thing: it starts one sync cycle. Run it on the Microsoft Entra Connect server, as SYSTEM or an administrator. The ADSync module comes with Entra Connect, and the Cloud Sync agent does not have it. It reads the sync scheduler first and refuses to start when a cycle is already running, which ends in an error so your RMM can try again later. A server in staging mode does not export to Entra ID, so the run is skipped there.
Delta, the default, processes only the changes since the last cycle. Initial runs a full import and sync of every connector. It is much heavier and can run for hours on a large directory, so use it after changing sync rules or filters, and start it in quiet hours.
It waits up to TimeoutSeconds (0 to 7200, default 600; 0 starts the cycle and does not wait), then reads the run results that appeared during the wait and reports each connector run. A result other than success ends the script as an error with the results listed. If the time runs out while the cycle is still running, the run still ends CHANGED, because the cycle was started, and says it was still running.
A sync cycle is an event, not a state, so there is no already done: a second run starts a second cycle. With DryRun=true or -WhatIf it lists the cycle it would start and changes nothing. If Get-ADSyncRunProfileResult is missing or cannot return results, it reports that the cycle finished without results.
Before You Run It
- Run it on the Entra Connect server itself, as SYSTEM or from an elevated PowerShell.
- Use the active server. A server in staging mode is skipped.
- Use Delta for an ordinary change. Keep Initial for after a change to sync rules or filters, and start it in quiet hours.
- Run it with DryRun=true first if you want to see the cycle it would start.
- If a cycle is already running it stops with an error. Wait a few minutes and run it again.
Type and Risk
- Type: Action. It makes its change, checks the change worked and says what changed. It exits 0, or 2 when it could not do the job.
- Risk: Low. Set DryRun=true, or run it with -WhatIf, to list every change without making any.
- What it changes: Starts one Entra Connect sync cycle (Delta or Initial).
- Restart: It never restarts the machine.
- Typical run: 1 to 10 minutes while it waits.
- Example answer: "Delta sync finished in 74 s: 4 connector run(s), all success"
- Tested before listing on a Windows Server 2025 domain controller (VM) with Windows PowerShell 5.1, run as SYSTEM, against its own test cases.
Inputs
Pass an input as an argument (-Name value), as an environment variable with the same name, which is how most RMMs pass script variables, or change its default in the param() block at the top of the script. An argument wins over an environment variable, which wins over the default.
- PolicyType: Delta (default) or Initial.
- TimeoutSeconds: How long to wait for the cycle to finish. Whole number, 0 to 7200; 0 = do not wait. Default 600. When the time runs out while the cycle is still running, the run still ends CHANGED (the cycle was started) and says it was still running.
Every script also takes DryRun, OutputFormat (Text, Answer, Json or Csv), ExportPath and ResultField, which writes the answer to an RMM custom field.
License
Provided "as is" under the MIT License, without warranty of any kind. Test before production use. MSP Outpost and User First Digital Inc. accept no liability for any damage or loss.