Kaseya Community

Configuring NTP (Time Servers) for All

  • Heres a script that I have written to update all time servers and restart synchronisation.

    This will work on windows machines, domain controllers, member servers, and workstation machines.

    (I beleive that some of the commands I use only work from Windows 2003+ or XP+)


    Script Name: Set SNTP (Time Servers)
    Script Description: IF NOT IN DOMAIN
    w32tm /config "/manualpeerlist:0.pool.ntp.org 1.pool.ntp.org 2.pool.ntp.org pool.ntp.org,0×8" /syncfromflags:MANUAL /reliable:yes /update
    net stop w32time && net start w32time && w32tm /resync /rediscover
    ELSE
    w32tm /config "/manualpeerlist:0.pool.ntp.org 1.pool.ntp.org 2.pool.ntp.org pool.ntp.org,0×8" /syncfromflags:MANUAL /reliable:yes /update
    @for /f "skip=8 Tokens=1,3" %i in ('net accounts') do @if /i "%i"=="Computer" if /i "%j"=="PRIMARY" (net stop w32time && net start w32time && w32tm /resync /rediscover) ELSE IF "%j"=="BACKUP" (net stop w32time && net start w32time && w32tm /resync /rediscover)
    echo y | net time /DOMAIN:#Domain# /set

    IF Check Registry Value
    Parameter 1 : HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Services\Tcpip\Parameters\Domain
    Not Contains :.
    THEN
    Execute Shell Command
    Parameter 1 : w32tm /config "/manualpeerlist:0.pool.ntp.org 1.pool.ntp.org 2.pool.ntp.org pool.ntp.org,0×8" /syncfromflags:MANUAL /reliable:yes /update
    Parameter 2 : 0
    OS Type : 0
    Execute Shell Command
    Parameter 1 : net stop w32time && net start w32time && w32tm /resync /rediscover
    Parameter 2 : 0
    OS Type : 0
    ELSE
    Execute Shell Command
    Parameter 1 : w32tm /config "/manualpeerlist:0.pool.ntp.org 1.pool.ntp.org 2.pool.ntp.org pool.ntp.org,0×8" /syncfromflags:MANUAL /reliable:yes /update
    Parameter 2 : 0
    OS Type : 0
    Execute Shell Command
    Parameter 1 : @for /f "skip=8 Tokens=1,3" %i in ('net accounts') do @if /i "%i"=="Computer" if /i "%j"=="PRIMARY" (net stop w32time && net start w32time && w32tm /resync /rediscover) ELSE IF "%j"=="BACKUP" (net stop w32time && net start w32time && w32tm /resync /rediscover)
    Parameter 2 : 0
    OS Type : 0
    Get Variable
    Parameter 1 : 0
    Parameter 2 : HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Services\Tcpip\Parameters\Domain
    Parameter 3 : Domain
    OS Type : 0
    Execute Shell Command
    Parameter 1 : echo y | net time /DOMAIN:#Domain# /set
    Parameter 2 : 0
    OS Type : 0


    Legacy Forum Name: Configuring NTP (Time Servers) for All,
    Legacy Posted By Username: sam.taylor
  • Do something similar but use two scripts. One to sync Domain Controllers to pool.ntp.org and one to sync Domain computers to the Domain Controllers.

    Script Name: Set Domain Controller to NTP time
    Script Description:

    IF True
    THEN
    Set Registry Value
    Parameter 1 : HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Services\W32Time\Parameters\Type
    Parameter 2 : NTP
    Parameter 3 : REG_SZ
    OS Type : 0
    Set Registry Value
    Parameter 1 : HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Services\W32Time\Config\AnnounceFlags
    Parameter 2 : 5
    Parameter 3 : REG_DWORD
    OS Type : 0
    Set Registry Value
    Parameter 1 : HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Services\W32Time\TimeProviders\NtpClient\Enabled
    Parameter 2 : 1
    Parameter 3 : REG_DWORD
    OS Type : 0
    Set Registry Value
    Parameter 1 : HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Services\W32Time\Parameters\NtpServer
    Parameter 2 : 0.pool.ntp.org,0x1 1.pool.ntp.org,0x1 2.pool.ntp.org,0x1
    Parameter 3 : REG_SZ
    OS Type : 0
    Set Registry Value
    Parameter 1 : HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Services\W32Time\TimeProviders\NtpClient\SpecialPollInterval
    Parameter 2 : 900
    Parameter 3 : REG_DWORD
    OS Type : 0
    Set Registry Value
    Parameter 1 : HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Services\W32Time\Config\MaxPosPhaseCorrection
    Parameter 2 : 3600
    Parameter 3 : REG_DWORD
    OS Type : 0
    Set Registry Value
    Parameter 1 : HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Services\W32Time\Config\MaxNegPhaseCorrection
    Parameter 2 : 3600
    Parameter 3 : REG_DWORD
    OS Type : 0
    Execute Shell Command
    Parameter 1 : net stop w32time
    Parameter 2 : 1
    OS Type : 0
    Execute Shell Command
    Parameter 1 : net start w32time
    Parameter 2 : 1
    OS Type : 0
    Execute Shell Command
    Parameter 1 : w32tm /resync /rediscover
    Parameter 2 : 1
    OS Type : 0
    Write Script Log Entry
    Parameter 1 : Set Domain Controller to NTP time ran successfully.
    OS Type : 0
    ELSE



    Script Name: Set Domain Computers time to DC
    Script Description:

    IF True
    THEN
    Execute Shell Command
    Parameter 1 : w32tm /config /syncfromflagsBig Smileomhier /update
    Parameter 2 : 1
    OS Type : 0
    Execute Shell Command
    Parameter 1 : net stop w32time
    Parameter 2 : 1
    OS Type : 0
    Execute Shell Command
    Parameter 1 : net start w32time
    Parameter 2 : 1
    OS Type : 0
    Write Script Log Entry
    Parameter 1 : Set Domain Computers time to DC ran successfully.
    OS Type : 0
    ELSE



    Legacy Forum Name: Scripts Forum,
    Legacy Posted By Username: jeremyj
  • Procedure Set Domain Computers time to DC.xml

    I've attached the above 2 scripts in K2 format. They're also below for the people who want to copy/paste

    &#65279;<?xml version="1.0" encoding="utf-8"?>
    <ScriptExport xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns="http://www.kaseya.com/vsa/2008/12/Scripting">
      <Procedure name="Set Domain Controller to NTP Time" treePres="3">
        <Body>
          <Statement description="" name="SetRegistryValue" continueOnFail="false">
            <Parameter xsi:type="StringParameter" name="RegistryPath" value="HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Services\W32Time\Parameters\Type" />
            <Parameter xsi:type="StringParameter" name="Value" value="NTP" />
            <Parameter xsi:type="EnumParameter" name="DataType" value="String" />
          </Statement>
          <Statement description="" name="SetRegistryValue" continueOnFail="false">
            <Parameter xsi:type="StringParameter" name="RegistryPath" value="HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Services\W32Time\Config\AnnounceFlags" />
            <Parameter xsi:type="StringParameter" name="Value" value="5" />
            <Parameter xsi:type="EnumParameter" name="DataType" value="Integer" />
          </Statement>
          <Statement description="" name="SetRegistryValue" continueOnFail="false">
            <Parameter xsi:type="StringParameter" name="RegistryPath" value="HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Services\W32Time\TimeProviders\NtpClient\Enabled" />
            <Parameter xsi:type="StringParameter" name="Value" value="1" />
            <Parameter xsi:type="EnumParameter" name="DataType" value="Integer" />
          </Statement>
          <Statement description="" name="SetRegistryValue" continueOnFail="false">
            <Parameter xsi:type="StringParameter" name="RegistryPath" value="HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Services\W32Time\Parameters\NtpServer" />
            <Parameter xsi:type="StringParameter" name="Value" value="0.pool.ntp.org,0x1 1.pool.ntp.org,0x1 2.pool.ntp.org,0x1" />
            <Parameter xsi:type="EnumParameter" name="DataType" value="String" />
          </Statement>
          <Statement description="" name="SetRegistryValue" continueOnFail="false">
            <Parameter xsi:type="StringParameter" name="RegistryPath" value="HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Services\W32Time\TimeProviders\NtpClient\SpecialPollInterval" />
            <Parameter xsi:type="StringParameter" name="Value" value="900" />
            <Parameter xsi:type="EnumParameter" name="DataType" value="Integer" />
          </Statement>
          <Statement description="" name="SetRegistryValue" continueOnFail="false">
            <Parameter xsi:type="StringParameter" name="RegistryPath" value="HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Services\W32Time\Config\MaxPosPhaseCorrection" />
            <Parameter xsi:type="StringParameter" name="Value" value="3600" />
            <Parameter xsi:type="EnumParameter" name="DataType" value="Integer" />
          </Statement>
          <Statement description="" name="SetRegistryValue" continueOnFail="false">
            <Parameter xsi:type="StringParameter" name="RegistryPath" value="HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Services\W32Time\Config\MaxNegPhaseCorrrection" />
            <Parameter xsi:type="StringParameter" name="Value" value="3600" />
            <Parameter xsi:type="EnumParameter" name="DataType" value="Integer" />
          </Statement>
          <Statement description="" name="ExecuteShellCommand" continueOnFail="false">
            <Parameter xsi:type="StringParameter" name="Command" value="net stop w32time" />
            <Parameter xsi:type="EnumParameter" name="ExecuteAccount" value="System" />
            <Parameter xsi:type="BooleanParameter" name="Is64Bit" value="False" />
          </Statement>
          <Statement description="" name="ExecuteShellCommand" continueOnFail="false">
            <Parameter xsi:type="StringParameter" name="Command" value="net start w32time" />
            <Parameter xsi:type="EnumParameter" name="ExecuteAccount" value="System" />
            <Parameter xsi:type="BooleanParameter" name="Is64Bit" value="False" />
          </Statement>
          <Statement description="" name="ExecuteShellCommand" continueOnFail="false">
            <Parameter xsi:type="StringParameter" name="Command" value="w32tm /resync /rediscover" />
            <Parameter xsi:type="EnumParameter" name="ExecuteAccount" value="System" />
            <Parameter xsi:type="BooleanParameter" name="Is64Bit" value="False" />
          </Statement>
          <Statement description="" name="WriteScriptLogEntry" continueOnFail="false">
            <Parameter xsi:type="StringParameter" name="Comment" value="Set Domain Controller to NTP Time ran Successfully" />
          </Statement>
        </Body>
      </Procedure>
    </ScriptExport>
    &#65279;<?xml version="1.0" encoding="utf-8"?>
    <ScriptExport xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns="http://www.kaseya.com/vsa/2008/12/Scripting">
      <Procedure name="Set Domain Computers time to DC" treePres="3">
        <Body description="DO NOT RUN THIS ON DOMAIN CONTROLLERS!!!">
          <Statement description="" name="ExecuteShellCommand" continueOnFail="false">
            <Parameter xsi:type="StringParameter" name="Command" value="w32tm /config /syncfromflagsBig Smileomhier /update" />
            <Parameter xsi:type="EnumParameter" name="ExecuteAccount" value="System" />
            <Parameter xsi:type="BooleanParameter" name="Is64Bit" value="False" />
          </Statement>
          <Statement description="" name="ExecuteShellCommand" continueOnFail="false">
            <Parameter xsi:type="StringParameter" name="Command" value="net stop w32time" />
            <Parameter xsi:type="EnumParameter" name="ExecuteAccount" value="System" />
            <Parameter xsi:type="BooleanParameter" name="Is64Bit" value="False" />
          </Statement>
          <Statement description="" name="ExecuteShellCommand" continueOnFail="false">
            <Parameter xsi:type="StringParameter" name="Command" value="net start w32time" />
            <Parameter xsi:type="EnumParameter" name="ExecuteAccount" value="System" />
            <Parameter xsi:type="BooleanParameter" name="Is64Bit" value="False" />
          </Statement>
          <Statement description="" name="WriteScriptLogEntry" continueOnFail="false">
            <Parameter xsi:type="StringParameter" name="Comment" value="Set Domain Computers time to DC ran successfully" />
          </Statement>
        </Body>
      </Procedure>
    </ScriptExport>


    Legacy Forum Name: Scripts Forum,
    Legacy Posted By Username: Charles.IN



    [edited by: Brendan Cosgrove at 12:50 PM (GMT -8) on 12-13-2010] .
  • Procedure Set Domain Controller to NTP Time.xml
    Attachment refers to previous post.

    Legacy Forum Name: ,
    Legacy Posted By Username: Charles.IN