Useful console commands

Time synchronization

One of the options of the net command allows us to synchronize time of the current computer with another computer on the network. The syntax of this command is:
NET TIME [\\computername | /DOMAIN[:domainname] | /RTSDOMAIN[:domainname]] [/SET]
NET TIME [\\computername] /QUERYSNTP
NET TIME [\\computername] /SETSNTP[:ntp server list]
The net time command synchronizes the computer's clock with that of another computer or domain, or displays the time for a computer or domain. When used without options on a Windows Server domain, it displays the current date and time at the computer designated as the time server for the domain. This command allows setting the NTP timeserver for computername.
Option Description
\\computername Is the name of the computer you want to check or synchronize with.
/DOMAIN[:domainname] Specifies to synchronize the time from the Primary Domain Controller of domainname.
/RTSDOMAIN[:domainname] Specifies to synchronize with a Reliable Time Server from domainname.
/SET Synchronizes the computer's time with the time on the specified computer or domain.
/yes Used with setting time when no further confirmation is desired.
/QUERYSNTP Displays the currently configured NTP server for this computer
/SETSNTP[:ntp server list] Sets the NTP time servers to be used by this computer. This may be a list of IP addresses or DNS names separated by spaces. If multiple timeservers are listed, the list must be surrounded by quotes.

Note: When the /DOMAIN switch is used with the NET TIME command, the computer sending a command to determine the PDC of the domain. After the PDC is known, a call is made to synchronize the time with the PDC. To force a computer to synchronize its time with a specific computer, send the following command:

NET TIME \\ /SET /Y 
or
NET TIME \\ /SET /Y 
On computers running Windows NT 4.0 (and higher) with Service Pack 3 installed, an environment variable called LogonServer is set to the validating domain controller. The LogonServer variable can be used to load balance the time source responsibility by sending the following command:
NET TIME %LOGONSERVER% /SET /Y 
When using NET TIME /DOMAIN:<DomainName>, a browse list is never requested from the domain listed to obtain a list of time source (TS) servers. This may cause problems if the PDC is not the domain time source server because some applications may be highly time sensitive. For example, all servers in a resource domain may be required to synchronize their time with the master account domain's time source server or servers. Rather than synchronizing the time with the account domain's time source server, the client computer will synchronize time with the account domain's PDC. A time source server advertises itself through the browser announcement. A Windows NT client or Windows 95 client should use the browse list to determine the time source server or servers available with which to synchronize time (this works as expected using NET TIME without the /DOMAIN switch). A computer can be configured to be a domain time source server by adding the TIMESOURCE value (Reg_DWord) under the following registry key and setting the value to 1:
HKEY_LOCAL_MACHINE\System\CurrentControlSet\Services\LANManServer\Parameters
When NET TIME /SET is sent without the /DOMAIN switch, the computer will obtain a browse list for the domain in which it is a member, select a time source server from the list, and then send a NetrRemoteTOD call to synchronize the time.

Scheduled tasks

To schedule job execution at a particular time or repetitively we can use AT console command. With this command we can schedule tasks anywhere on the network and we don't have to log on to remote systems (we may need special permissions to do so, though). The general syntax of the command is
AT [\\computername] time [/INTERACTIVE] [ /EVERY:date[,...] | /NEXT:date[,...]] "command"
or
AT [\\computername] [ [id] [/DELETE] | /DELETE [/YES]]
where
Option Description
\\computername Specifies a remote computer. Commands are scheduled on the local computer if this parameter is omitted.
id Is an identification number assigned to a scheduled command.
/delete Cancels a scheduled command. If id is omitted, all the scheduled commands on the computer are canceled.
/yes Used with cancel all jobs command when no further confirmation is desired.
time Specifies the time when command is to run.
/interactive Allows the job to interact with the desktop of the user who is logged on at the time the job runs.
/every:date[,...] Runs the command on each specified day(s) of the week or month. If date is omitted, the current day of the month is assumed.
/next:date[,...] Runs the specified command on the next occurrence of the day (for example, next Thursday). If date is omitted, the current day of the month is assumed.
"command" Is the Windows NT command, or batch program to be run.
Examples: Note: please notice that we need to use 24-hour time to schedule jobs (or we need to use AM or PM suffix after the time). When we use numeric dates (like in /every option) we can use any value in the range 1-31. We can also schedule tasks by the day of the week. The values are:

Assignments

  1. Write a script that synchronizes computer time with a time server on a domain.
  2. Write a script that adds the previous script at the StartUp folder.
  3. Write a script that schedules script 1 to execute three times a week.
  4. Write a script that performs backup for a directory that is given as script's argument.
  5. Write a script that schedules the previous script to execute every other day at 3am.