What It Does
The script is read-only. It checks three things, one row each. The Windows Time service, W32Time, is either running or not, and a stopped service is an alert. The configured time source is read from the registry, from the Type and NtpServer values under W32Time Parameters: Type NT5DS on a domain-joined PC means it syncs from the domain hierarchy, Type NTP means the listed NtpServer, AllSync means both, and NoSync means none.
The clock offset is measured by requesting three samples from ReferenceServer with w32tm /stripchart in data-only mode. It sorts the signed numeric readings and takes the middle, or the lower middle if only two are readable. It then compares the absolute offset with MaxOffsetSeconds.
If no numeric offsets are returned, the run ends ERROR. An unreachable reference or blocked UDP port 123 can cause this. On a domain-joined PC whose firewall blocks internet time, set ReferenceServer to a domain controller. The offset is measured, not corrected: nothing is resynchronised.
Before You Run It
- On domain-joined PCs, set ReferenceServer to a domain controller so the check measures the right thing.
- Make sure UDP port 123 to the reference server is open, or the run ends in ERROR.
- Set MaxOffsetSeconds to match what your services tolerate. The default is 60.
- Schedule it daily in your RMM and alert on exit 1.
Type and Risk
- Type: Monitor. It checks one condition. It exits 1 when it finds the problem, so your RMM can alert on it, 0 when all is well, and 2 when it could not run.
- Risk: Low. It reads and changes nothing.
- Restart: It never restarts the machine.
- Typical run: Under 20 seconds.
- Example answer: "Clock is 142.300 s from time.windows.com (limit 60 s); W32Time running; source NTP time.windows.com,0x9"
- Tested before listing on Windows 11 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.
- ReferenceServer: Host name or IP address of the time server to measure against. Letters, digits, dots, dashes and colons only. Default time.windows.com.
- MaxOffsetSeconds: Largest clock offset allowed, in seconds. Whole number, 1 to 86400. Default 60.
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.