2

Every time I add a computer to my network I run a script to set everything up as needed. One of the actions I need to perform is making the new computer's clock synchronize with a certain computer on the network (i.e. ip x.x.x.x).

I know I could make it sync once using:

NET TIME \\x.x.x.x /SET /Y

But I want the computers to stay synced with x.x.x.x (as would happen with an internet server if I manually chose "synchronize with an internet time server" in "internet time settings").

Is there a Powershell command that will change Windows' settings so it will keep sync with x.x.x.x? (I know I can write a script to run the above command e.g. every day and make it run on startup on each of the machines on the network, but I prefer adding a line (or a couple) to the script I run once when setting up a new machine)

Thank you!

shayelk
  • 1,606
  • 1
  • 14
  • 32
  • What is enforcing the time server now? Group Policy? It sounds like something is doing it. – Matt Mar 30 '16 at 13:52
  • 1
    Duplicate? It's not technically powershell, but you can certainly run these commands from a powershell script. http://stackoverflow.com/questions/22862236/how-to-sync-windows-time-from-a-ntp-time-server-in-command – Brett Green Mar 30 '16 at 14:03
  • Matt, currently we update the time manually every once in a while using the command in the OP. BrettGreen, I'll try it out, thank you! – shayelk Mar 31 '16 at 10:57

1 Answers1

3

You can configure the Windows time service (w32time) with the w32tm tool to sync from another machine (via NTP) in PowerShell like this:

Start-Process w32tm -ArgumentList "/config /update /manualpeerlist:x.x.x.x /syncfromflags:MANUAL"

Where:

  • x.x.x.x is your IP address
  • /config to configure w32time service
  • /update to apply the new config immediately
  • /manualpeerlist: to define the source where to sync from
  • /syncfromflags:MANUAL to make sure that no other sources than the manually defined peer list are used
stackprotector
  • 10,498
  • 4
  • 35
  • 64
  • Thanks for resolve my WMI problem `Get-WmiObject : A security package specific error occurred. (Exception from HRESULT: 0x80070721)`. – LauZyHou Oct 28 '22 at 02:25