Quantcast
Channel: The Official Scripting Guys Forum! forum
Viewing all articles
Browse latest Browse all 15028

Help with LastReboot.vbs

$
0
0

Hello, I was able to get the following script to work, but wanted the output to be report.csv with columsComputer, Last Reboot and Online Since

Any help would be greatly appreciated!

********************************************************************
'* File: LastReboot.vbs
'* Author: Manoj Nair | Created on 09/10/2009
'* Version 1.0
'*
'* Main Function: Displays the last reboot time of a computer
'*
'********************************************************************
 
On Error Resume Next
Const ForReading = 1
Set objFSO = CreateObject("Scripting.FileSystemObject")
 
    ' =====================================================================
     'Gets the script to run against each of the computers listed 
     'in the text file path for which should be specified in the syntax below
    ' =====================================================================
Set objTextFile = objFSO.OpenTextFile("F:\Fepstools\GetLastReboot\servers.txt", ForReading)
Set outfile = objFSO.CreateTextFile("Report.txt")
Do Until objTextFile.AtEndOfStream 
    strComputer = objTextFile.Readline
    ' ===============================================================================
    ' Code to get the Last Boot Time using LastBootupTime from Win32_Operating System
    ' ===============================================================================
Set objWMIService = GetObject _
    ("winmgmts:\\" & strComputer & "\root\cimv2")
Set colOperatingSystems = objWMIService.ExecQuery _
    ("Select * from Win32_OperatingSystem")
For Each objOS in colOperatingSystems
    dtmBootup = objOS.LastBootUpTime
    dtmLastBootupTime = WMIDateStringToDate(dtmBootup)
    'OutFile.WriteLine "=========================================="
    OutFile.WriteLine "Computer: " & strComputer
    OutFile.WriteLine "Last Reboot: " & dtmLastBootupTime
    dtmSystemUptime = DateDiff("h", dtmLastBootUpTime, Now)   
    OutFile.WriteLine "System is online since " & dtmSystemUptime & " hours"
    OutFile.WriteLine "=========================================="
    
    
Next
 
    ' =====================================================================
    ' End
    ' =====================================================================
Loop
objTextFile.Close
 ' ===============================================================================
 ' Displaying to the user that the script execution is completed
 ' ===============================================================================
MsgBox "Script Execution Completed. The Report is saved as Report.txt in the current directory"
 ' ===============================================================================
 ' Function to convert UNC time to readable format
 ' ===============================================================================
Function WMIDateStringToDate(dtmBootup)
    WMIDateStringToDate = CDate(Mid(dtmBootup, 5, 2) & "/" & _
         Mid(dtmBootup, 7, 2) & "/" & Left(dtmBootup, 4) _
         & " " & Mid (dtmBootup, 9, 2) & ":" & _
         Mid(dtmBootup, 11, 2) & ":" & Mid(dtmBootup, _
         13, 2))
End Function


Viewing all articles
Browse latest Browse all 15028

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>