The VBScript Network and Systems Administrator's Cafe

Nov 10 2008   4:01AM GMT

Getting the date and time from a remote system via WMI and the WIN32_LocalTime class

Jerry Lees Jerry Lees Profile: Jerry Lees

Recently, after the time change I had to log into around 30 to 40 servers to check that the date was correct. This was a real pain, since it required me to actually log onto the server via terminal services and run a command prompt to issue a date command.

Unfortunately, I didn’t have a script written to do this remotely with WMI and I needed to get it done very quickly… so I had to do it the long, old fashioned, and unlazy way. Shortly after this I wrote the following function to check the date on a remote server using the WMI Win32_LocalTime class! Notice the class name is “Local Time”, and that’s just what it is… the local time of the system. However, if you run it on a remote system it returns the local time of the remote system!

Here is the function I wrote:

WScript.Echo GetDate(“.”)

Function GetDate(strcomputer)
on Error resume next
Set objWMIService = GetObject(“winmgmts:{impersonationLevel=impersonate}!\\” & strComputer & “\root\cimv2”)

Set ColDate = objWMIService.ExecQuery(“Select * from Win32_LocalTime”)

for each objDate in ColDate
GetDate = ObjDate.Month & “/” & ObjDate.Day & “/” & ObjDate.Year

‘cleanup memory
objWMIService = Nothing
End Function

2  Comments on this Post

There was an error processing your information. Please try again later.
Thanks. We'll let you know when a new response is added.
Send me notifications when other members comment.
  • Bplotkin
    This script doesn't run properly is there something i am missing? What i need is to pull all the times and corresponding host names of remote servers and put it into an easy to compare format (xls, html...) also continually update this every few minutes or so. Thanks!
    0 pointsBadges:
  • Msant
    The script does do that, except the update every few minutes-- which would just be a simple loop to implement. Can you elaborate on the error you are getting?
    240 pointsBadges:

Forgot Password

No problem! Submit your e-mail address below. We'll send you an e-mail containing your password.

Your password has been sent to:

Share this item with your network: