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
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