in

This Blog

Syndication

Advertising

mystyleit

October 2007 - Posts

  • Pulling System Date and Time into Variables

    It can be very useful to pull the date and time from the system and put it into variables. Once the date and time are in variables, they can be used to build filenames for log file, etc

    First off, make sure the Regional Settings are set to the following:

    The following script will pull the numerical date and time into variables.

    REM ***************************************************************************
    REM time variables

    set month=%date:~4,2%
    set day=%date:~7,2%
    set year=%date:~10,4%

    for /f "tokens=5-7 delims=:. " %%a in (
    'echo/^|time^|find "current"'
    ) do set hour=%%a&set minute=%%b&set second=%%c

    ECHO YEAR:%YEAR%
    ECHO MONTH:%MONTH%
    ECHO DAY:%DAY%

    ECHO HOUR:%HOUR%
    ECHO MINUTE:%MINUTE%
    ECHO SECOND:%SECOND%

    Now that you've got the date and time in variables, building a file name that contains the date and time is a snap.

    SET logfile=%year%-%month%-%day% %hour%-%minute%-%second%.log
  • Synchronizing Windows 2000/2003 Server Clock with Internet Time Server

    Synchronizing Windows 2000/2003 Server Clock with Internet Time Server

    By default, Windows-based computers use the following hierarchy:

    • All client desktop computers nominate the authenticating domain controller as their in-bound time partner.
    • All member servers follow the same process as client desktop computers.
    • Domain controllers may nominate the primary domain controller (PDC) operations master as their in-bound time partner but may use a parent domain controller based on stratum numbering.
    • All PDC operations masters follow the hierarchy of domains in the selection of their in-bound time partner.

    It is therefore a good idea to synchronize your DC's with a Internet Time Server to ensure that your clock is up to date.

    Windows 2003 Script

    The following script will synchronize a Windows 2003 Server clock with a Internet Time Server. Generally, I create a batch script and schedule a Windows Task to run the script nightly.

    w32tm /config /manualpeerlist:"tick.usno.navy.mil" /syncfromflags:MANUAL
    w32tm /config /update
    net stop w32time
    net start w32time
    w32tm /resync /nowait

    Windows 2000 Script

    The script is different for Windows 2000, but performs the same function.

    net time /setsntp:tick.usno.navy.mil
    NET STOP w32time
    w32tm -once -v
    NET START w32time

    Ensure that the Network Time Protocol port, port 123, is open.

    References

    Posted Oct 15 2007, 03:28 PM by mike.clarke with no comments
    Filed under: