Synchronizing the local system to a central time source allows you to perform enterprise-wide tasks simultaneously. The basic syntax to synchronize the local clock with a specified time source is as follows:
Net Time \\server/commands
Here, \\server is the name of the time source server to sync with. This parameter is only necessary when syncing with a specific server. If this parameter is omitted (Net Time), the system will search the local domain for a time source server. /commands are any of the following parameters:
- /SET—Sets the local time to the time source server
- /Y—Forces to sync the time with the server specified, regardless of whether the server is a time source server or not
- /DOMAIN:domainname—Searches the specified domain for a time source server
The following script attempts to sync the local system time with the server named servername. If this fails, the domain will be searched for a time source to sync with. To execute this script, proceed as follows:
- Create a new directory to store all files included in this example.
- Select Start|Run and enter “scriptfile.bat.”
Here, scriptfile is the full path and file name of a script file that contains the following:
@Echo Off
CLS ; Clears the screen
Set TServer=ServerName
Echo Syncing the time with %TServer%…
Net Time \\%TServer% /set /yes
If %errorlevel% NEQ 0 CLS && Goto Domain
CLS && Echo Sync Successful
Goto End
Image may be NSFW.
Clik here to view. omain
Echo Searching the local domain for a time-server…
Net Time /set /yes
If %errorlevel% EQU 0 CLS && Echo Sync Successful && Goto End
CLS && Echo Time Sync Error
:End
Here, tserver is a variable containing the name of the time source server; NEQ is the “not equal to” operator; and && allows you to run a second command after the first has completed.
Image may be NSFW.
Clik here to view.

Clik here to view.
