I am attempting to run a script that returns the last reboot time. I found this script (author Alistair McMillan, 2011) :
Option Explicit ' Declare variables Dim colItems, objItem, objWMIService Dim strBoot, strBootDate, strBootDay, strBootHour, strBootMins Dim strBootMonth, strBootTime, strBootYear, strComputer, strMsg, strQuery strComputer = "." If IsEmpty(strComputer) Then WScript.quit() ElseIf strComputer = "" Then strComputer = "." End If ' Connect to specified computer Set objWMIService = GetObject( "winmgmts://" & strComputer & "/root/cimv2" ) Set colItems = objWMIService.ExecQuery( "Select * from Win32_OperatingSystem", , 48 ) For Each objItem in colItems strBootYear = Left( objItem.LastBootUpTime, 4 ) strBootMonth = Mid( objItem.LastBootUpTime, 5, 2 ) strBootDay = Mid( objItem.LastBootUpTime, 7, 2 ) strBootDate = DateValue( strBootDay & "-" & strBootMonth & "-" & strBootYear ) strBootHour = Mid( objItem.LastBootUpTime, 9, 2 ) strBootMins = Mid( objItem.LastBootUpTime, 11, 2 ) strBootTime = strBootHour & ":" & strBootMins strBoot = strBootDate & ", " & strBootTime strMsg = strBoot Next ' Display results Output.write strMsg 'Done 'WScript.Quit(0)
The script returns the datetime of the last reboot of the computer running the script. I've been pouring over this and can't seem to find my error. Can anyone help?
(To clarify: the script reads the top three machines on my CSV correctly then adds multiple lines for one machine repeatedly.)