Quick Script to Remotely Check Windows System Time

scriptThe business had a requirement to validate the time on a handful of remote Windows XP machines to ensure that their times were all synchronized. This audit point was a show stopper and required a solution ASAP. The current solution was to VNC to the system and visually validate the time. I started thinking that there must be a way to remotely check this from a script so I posted a call for help out on Twitter.

Special thanks to @domdingelmom for pointing me to the WMI Tasks: Dates and Times article on MSDN.

Using this link as a guide I was able to create the following visual basic script to make the remote call:

Set dtmInstallDate = CreateObject( _
"WbemScripting.SWbemDateTime")
strComputer = "__NETBIOS__"
Set objSWbemLocator = CreateObject("WbemScripting.SWbemLocator")
Set objSWbemServices = objSWbemLocator.ConnectServer _
(strComputer, "rootcimv2", _
"__DOMUSER__", "__PASSWORD__")
Set objOS = objSWbemServices.ExecQuery( _
"Select * from Win32_OperatingSystem")
For Each strOS in objOS
dtmInstallDate.Value = strOS.InstallDate
Wscript.Echo dtmInstallDate.GetVarDate
Next

Where:
– __NETBIOS__ is the NETBIOS name of the machine
– __DOMUSER__ is the user name allowed to make the query (e.g. DOMAINandrew)
– __PASSWORD__ is the password to authenticate

You then take the code and put it into a file called test.vbs. This should make validating the time a 5 second task by simply running: cscript test.vbs > results.txt

Not the most monumental scripting task ever undertaken but not bad for a guy who hates to code. With some further tweaking I hope to make this script capable of handling more than one system (possibly a list of systems) and allow for the input of credentials.

Enjoy 🙂

Scroll to top