3.13. Configuring a Domain Controller to Use an External Time Source

Problem

You want to set the reliable time source for a domain controller.

Solution

Using a command-line interface

Run the following commands from the command line on a domain controller:

> net time /setsntp:<TimeServerNameOrIP>
> net stop w32time
> net start w32time

Using VBScript

' This codes configures a reliable time source on a domain controller
' ------ SCRIPT CONFIGURATION ------
strPDC = "<DomainControllerName>"       ' e.g. dc01.rallencorp.com
strTimeServer = "<TimeServerNameOrIP>" ' e.g. ntp01.rallencorp.com ' ------ END CONFIGURATION --------- strTimeServerReg = "SYSTEM\CurrentControlSet\Services\W32Time\Parameters" const HKLM = &H80000002 set objReg = GetObject("winmgmts:\\" & strPDC & "\root\default:StdRegProv") objReg.GetStringValue HKLM, strTimeServerReg, "ntpserver", strCurrentServer WScript.Echo "Current Value: " & strCurrentServer objReg.SetStringValue HKLM, strTimeServerReg, "ntpserver", strTimeServer objReg.SetStringValue HKLM, strTimeServerReg, "type", "NTP" strCurrentServer = "" objReg.GetStringValue HKLM, strTimeServerReg, "ntpserver", strCurrentServer WScript.Echo "New Value: " & strCurrentServer ' Restart Time Service set objService = GetObject("winmgmts://" & strPDC & _ "/root/cimv2:Win32_Service='W32Time'") WScript.Echo "Stopping " & objService.Name objService.StopService( ) Wscript.Sleep 2000 ' Sleep for 2 seconds to give service time to stop WScript.Echo "Starting " & objService.Name objService.StartService( ...

Get Active Directory Cookbook now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.