WMI: Timezone and daylight savings check
I recently had a customer ask about checking time zone information on client workstations. After digging around Group Policy to see if there way any direct way to force the requested behavior on an OU, I came to the conclusion that a script might be the easiest way to find out if any workstations have the wrong time zone settings.
Specifically, I’m talking about the “Automatically adjust clock for daylight saving changes” box under “Date and Time Properties”, and determining if it’s unchecked. This type of issue tends to start out with individuals reporting something to the effect of... “Outlook calendars are an hour off”, or “when I view someone else’s Calendar, scheduled items run into the next day”.
Now, let me preface this post by saying that I’m not really a WMI expert like the guys over at the Microsoft’s script center. But I can hack together enough code to get the job done. In this case, the script will run against all computers in Active Directory, but you can easily modify it to work against an OU, or from a list of workstations. You’ll also want to make sure to specify the organization appropriate LDAP path in the select statement if you want to use what I already have .
And hey, this is the first time I've posted any code on this blog, so it might come out looking a little funny - when I copied and pasted from one of my scripts, I had to mess with formatting on just about every line.
On Error Resume Next
Const ADS_SCOPE_SUBTREE = 2
Const MegabyteConversion = 1048576
Const Warning_Threshold = 1000
Set objConnection = CreateObject("ADODB.Connection")
Set objCommand = CreateObject("ADODB.Command")
objConnection.Provider = "ADSDSOObject"
ObjConnection.Open "Active Directory Provider"
Set objCommand.ActiveConnection = objConnectionobjCommand.Commandtext = _
"Select Name from 'LDAP://dc=organization, dc=local' " _
& "Where objectClass='computer'"
objCommand.Properties("Page Size") = 1000obj
Command.Properties("Searchscope") = ADS_SCOPE_SUBTREE
Set objRecordSet = objCommand.ExecuteobjRecordSet.MoveFirst
Do until objRecordSet.EOF
Computer = objRecordSet.Fields("Name").Value
Set objWMIService = GetObject("winmgmts:\\" & Computer & "\root\cimv2")
Set colItems = objWMIService.ExecQuery("Select * from Win32_ComputerSystem",,48) If Err.number <> 0
then 'Wscript.Echo Computer & ", " & Err.Description
'Err.clear Resets the error code
'UnavailableSystems = UnavailableSystems & "," & " " & Computer
UnavailableSystems = Computer & ", " & UnavailableSystems
Err.Clear
else
For Each objItem in colItems wscript.Echo "IP Address: " & Computer
Wscript.Echo "Caption: " & objItem.Caption
'CurrentTimeZone: Amount of time the comptuer is offset from UTC
Wscript.Echo "CurrentTimeZone: " & objItem.CurrentTimeZone
'DaylightInEffect: Boolean, if true then daylight savings mode is on.
Wscript.Echo "DaylightInEffect: " & objItem.DaylightInEffect
If objItem.DaylightInEffect = True Then
dltrue = dltrue + Computer & " "
Else
End If
Wscript.Echo "DomainRole: " & objItem.DomainRole
Wscript.Echo "UserName: " & objItem.UserName
Wscript.Echo " "
Next
End If
Err.Clear
objRecordSet.MoveNext
Loop
Wscript.Echo "Unavailable Systems: " & UnavailableSystems
Wscript.Echo "Daylight savings=True: " & dltrue
Wscript.Echo "Finished..."
No comments:
Post a Comment