O'Reilly logo

Active Directory Cookbook by Robbie Allen

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

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( ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required