Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations IamaSherpa on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

objItem.LocalDateTime formatting Issues 1

Status
Not open for further replies.

BumpBump

Technical User
Sep 9, 2004
5
US
Here is the Script in question.
I want to pull the datetime and time zone from the machines listed in the text file. This all works very well it is formatting issues I am having with the date and time. Do you all have any suggestions for me.
I plan on using a Select case to get the timezone into a format more readable such as -5 = EST etc.

On Error Resume Next
Const ForReading = 1
Const ForWriting = 2 'Will overwrite the file without asking.
Const ForAppending = 8
Set Computer = GetObject("winmgmts:\\InaccessibleComputer")
Set objFSO = CreateObject("Scripting.FileSystemObject")
txtinput = InputBox("Enter the File name","Output File Name")
Set objTextFile = objFSO.OpenTextFile("C:\"&txtinput&".csv", ForWriting, True)
Set objReadFile = objFSO.OpenTextFile("C:\Computers.txt", ForReading)
objTextFile.Write("Server Name , Date & Time , Time Zone(Hours off of GMT)")
objTextFile.Writeline
Err.Clear

Do While objReadFile.AtEndOfStream = False
strComputer = objReadFile.ReadLine
Set objWMIService = GetObject("winmgmts:\\" & strComputer & "\root\cimv2")
Set colItems = objWMIService.ExecQuery("Select * from Win32_OperatingSystem",,48)
For Each objItem in colItems
Wscript.Echo "Name: " & objItem.CSName
Wscript.Echo "LocalDateTime: " & Mid(objItem.LocalDateTime,8,6)
Wscript.Echo "CurrentTimeZone: " & objItem.CurrentTimeZone/60
WriteFile
Next

Loop


Function WriteFile
If Err = 462 Then
objTextFile.WriteLine(strComputer & ", The Remote Server does not exist or is unavailable.")
Err.Clear
ElseIf Err <> 0 Then
objTextFile.WriteLine(strComputer & ", Error: "& Err.Description)
Err.Clear
Else
objTextFile.WriteLine(objItem.CSName & "," & objItem.LocalDateTime& "," & objItem.CurrentTimeZone)
Err.Clear
End If
End Function
 
Hello BumpBump,

You can set up a dictionary to start with and reference back to it when display. Like this.
Code:
'timezone dictionary
'ref [URL unfurl="true"]http://aa.usno.navy.mil/faq/docs/world_tzones.html[/URL]
set odic=createobject("scripting.dictionary")
with odic
	.add 0,"Z" : .add 1,"A" : .add 2,"B" : .add 3,"C" : .add 3.5,"C*" 
	.add 4,"D" : .add 5,"E" : .add 6,"F" : .add 7,"G" : .add 8,"H"
	.add 9,"I" : .add 9.5,"I*" : .add 10,"K" : .add 10.5,"K*" : .add 11,"L"
	.add 11.5,"L*" : .add 12,"M" : .add 13,"M*" : .add 14,"M+" : .add -1,"N"
	.add -2,"O" : .add -3,"P" : .add -4,"Q" : .add -5,"R" : .add -6,"S"
	.add -7,"T" : .add -8,"U" : .add -8.5,"U*" : .add -9,"V" : .add -9.5,"V*"
	.add -10,"W" : .add -11,"X" : .add -12,"Y"
end with
and display as:
[tt]
Wscript.Echo "CurrentTimeZone: " & odic.item(objItem.CurrentTimeZone/60)
[/tt]
You can sure replace zone "R" by "Est" etc. for better mental capture.

Just a suggestion.

regards - tsuji
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top