HOWTO: Work with ntp via Powershell


In this article we will discuss the main points of working with ntp through Powershell on Windows server 2012. We will do this on the domain controller. So let's get started.


1. Start and stop time service:

   - Use this commands:
net start w32time
net stop w32time
or
stop-service w32time
start-service w32time

2. Let's specify the server with which we will synchronize time:

   - Check if our time is synchronized with Microsoft's public ntp server:
w32tm /stripchart /computer:time.windows.com /samples:4 /dataonly

3. Let's specify the server with which we will synchronize time:

   - Check if our time is synchronized with Microsoft's public ntp server:
w32tm /stripchart /computer:time.windows.com /samples:4 /dataonly

4. Choose trusted time source:

   - Now we’ll point out that we have to synchronize with this server and say that we are a trusted time source:
w32tm /config /manualpeerlist: time.windows.com /syncfromflags:manual /reliable:yes /update

5. Synchronize with several public time sources:

   - If you need to synchronize with several public time sources, the command will look like this:
w32tm /config /manualpeerlist:"ntp1.sp.se ntp2.sp.se" /syncfromflags:MANUAL /reliable:yes /update

6. Several useful commands:

   - Useful information about time synchronization: w32tm /query /status
Command to debug to file:
w32tm / debug / enable / file: C: \ folder name \ file name.txt / size: 10485760 / entries: 0-300
After debug let's turn it off:
w32tm /debug /disable
Command to forcing client sync:
w32tm /resync
To reset the settings, use the command:
w32tm /unregister
Next, restore the default settings:
w32tm /register

Also consider using Action1 to set time remotely if:
- You need to perform this action on multiple (hundreds or even thousands) computers simultaneously.
- Some of your endpoints are laptops not connected to corporate network at all times.

Action1 is a cloud-based platform for software deployment, software/hardware inventory, patch management, endpoint configuration and more. It is free with basic functionality.


Other Relevant HOWTOs: