I'm working with servers that don't have the W32Time service running, and I need to verify if they're getting the correct time from an alternative solution, specifically DomainTime II from Greyware. I'm looking for a way to test the servers to ensure that firewalls and IP resolution are functioning correctly, but I can't find a PowerShell solution that doesn't involve using w32tm. I did find a C# example and managed to convert it into a native PowerShell function called Get-NTPTime. This function can either use an IP address you provide or look for the Windows Time NTP server in the registry. It creates a socket request to query the time server and returns the time in either local or UTC format. I hope someone finds this helpful!
5 Answers
I created a similar script using ChatGPT, which connects directly to an NTP server of my choice. It’s a bit cleaner than restarting windows time services. We've found that if a remote PC's clock is significantly off, it can hinder remote session connections, but your script seems to be a good alternative for quickly syncing the time.
While I haven't tried your code yet, I use w32tm for checking non-Windows NTP servers, including some mainframes and Linux systems. I'm curious why DomainTime II isn't reporting correctly unless w32tm is enabled, which isn't the case for all our servers. We stopped relying on third-party options after Microsoft improved w32time with Windows Server 2016.
I modified your function to work with `-computername` too! It now supports not just Windows but also macOS and Linux systems. Here's a sample call: `Get-NTPTime -ComputerName $(Get-NTPServer)`, and it successfully returned the current time for me!
Consider setting a timeout to avoid infinite waits on bad addresses. Something like `$Socket.RetrieveTimeout = 5000` milliseconds could be helpful, especially if your firewall blocks requests.
This looks really interesting! Just a suggestion: consider adding a `-computername` parameter so you can directly use names like `pool.ntp.org` or specific IPs, just like `Test-NetConnection` and `Test-Connection`. You might need to adjust the handling of `[System.Net.IPEndPoint]` accordingly.

Related Questions
How To: Running Codex CLI on Windows with Azure OpenAI
Set Wordpress Featured Image Using Javascript
How To Fix PHP Random Being The Same
Why no WebP Support with Wordpress
Replace Wordpress Cron With Linux Cron
Customize Yoast Canonical URL Programmatically