Obtaining NTP Source and Delay (or drift)

I'm looking for the most accurate way to query the NTP source and the amount of drift from that NTP source.

Any advice or answers are welcome...
I've been throwing this question around and I usually get one of two responses;
  1. I have no idea how to even begin something like that
2. Ask someone else... I'm busy.
I'd really appreciate any input on this subject.

This looks to be a pretty thorough run through of one method.

The code is a little outdated and needs some TLC, but it should be serviceable. :slight_smile:

Seeing as it has a prerequisite of a Windows service, any more direct solutions would probably require some P/Invoke shenanigans.

Have used the following in a module.

   Helper function to perform the clock Drift test
   Helper function to perform the clock Drift test
function Test-ClockDrift
    # Get the clock drift by testing it aginst the google ntp service, one sample only.
    $timeDifference = w32tm.exe /stripchart /dataonly /computer:time.google.com /samples:1

    # The returned result is a string, split the string and get the time only.
    $clockDriftString = $timeDifference[3].Split(',')[1]

    # Remove any non-numeric characters.
    $clockDriftString = ($clockDriftString -Replace "[^0-9]{2}").Replace('s','').Replace(',','.')

    # Cast the string to decimal and round it to two decimals, this will also return the results.

This will compare the current machines clock with the NTP source you state in the command line.
Just modify it with whatever source (or parameterize it) you need etc.
Accurate when it comes to NTP will always be a question on how accurate you need it to be :slight_smile:

E.g. the above will only grab one sample, to get a better result you probably want to grab multiple samples and do an average on those.
When I wrote the above I only needed a ballpark figure just to see if it was completely out of wack (someone had reconfigured the PDC FSMO role on the wrong DC).

Excellent Fredrik!

This is exactly what I’ve been looking for.

Thank you VERY much!!