2

Essentially, I want to get an accurate time from a public NTP server, in DOS or powershell.
I know there's the w32tm which can query a remote ntp server, but the result it gives is how much out my computer time is, not the actual time of the remote ntp server.

I've found various windows apps that work exactly as I want, but i can't get the output to a variable to do anything with. I'm dead surprised there's no .exe that just gets the time from a source, or that it wasn't written into w32tm.

Something like ntpquery.exe pool.ntp.org (followed maybe like a timezone or something) with an output of the date / time is all I'm after.


I know there's a command on another question that shows this result:

w32tm /stripchart /computer:foo
Tracking foo [1.2.3.4].
The current time is 19/07/2012 17:39:48 (local time).
17:39:48 d:-00.0000840s o:-25.3004160s  [@                          |                           ]

This shows the local system time (which could and in my case is wrong) and how much out it is to the NTP server (example above is 0.00000840s)

If I run this I could get a result of +/- 3000 seconds or even more, which doesn't give me the actual time of the NTP server just tells me how out I am.


What I'm looking for is a way to get the time from the NTP source in DOS / powershell so I can use it as a variable.

Gnoupi
  • 8,108
  • 9
  • 43
  • 59
Schui1024
  • 41
  • 1
  • 1
  • 5
  • 5
    Does this answer your question? [How can I query an NTP server under Windows?](https://superuser.com/questions/451018/how-can-i-query-an-ntp-server-under-windows) – spikey_richie Aug 07 '20 at 21:05
  • 1
    What does this have to do with the MS-DOS operating system? – Ramhound Aug 07 '20 at 22:15
  • 2
    Please see this script on [TechNet](https://gallery.technet.microsoft.com/scriptcenter/Get-Network-NTP-Time-with-07b216ca). You can then include this into your powershell script and use it like this: `$NTPTime = (Get-NtpTime).NtpTime`. This will store the time returned from the default ntp server (pool.ntp.org) in a DateTime data type. You can change which NTP server by using the `-server` parameter. – CraftyB Aug 09 '20 at 09:57
  • @spikey_richie the other question is a general Windows one, while this one is about doing it in cmd/powershell. Also the other question's only cmd answer uses w32tm and OP is looking for another solution. I'd say not a duplicate. – Gnoupi Aug 10 '20 at 16:46
  • @CraftyB this should be an answer, not just a comment. – Gnoupi Aug 10 '20 at 17:14

1 Answers1

0

Thanks for all the responses... esp CraftyB.... though I figured out a way to do it in the end and thought I'd share with.

What I did was use this app here (free) https://www.meinbergglobal.com/english/sw/ntp.htm Installed.. then took the libcrypto-1_1.dll and ntpdate.exe from the installation and scripted that to get the result from a remote ntp server.

Works fab. Thanks so much for everyone's input - and CraftyB your response is a valid answer that also works.. so I may migrate to that in the end !

Schui1024
  • 41
  • 1
  • 1
  • 5