VBScript to find out last reboot for multiple computers

' Description  : This script will display the Last reboot of the machines in a '                     Excel file
' Instructions : Create a text file by name servers.txt in C: drive with the server '                     names which u need to check the Last Reboot. Output will be '                     an excel file which will be saved in C: drive with file name as '                     "LastReboot_<date> <time>.xls"

              

Dim objExcel, objWorkbook, objWorksheet, objRange
Dim objNtpad, objFile

Const ForReading = 1


'Opening the Input file
Set objFSO = CreateObject("Scripting.FileSystemObject")
Set objFile = objFSO.OpenTextFile("C:\servers.txt", ForReading)

Set WSHShell = WScript.CreateObject("WScript.Shell")

On Error Resume Next
Set objExcel = CreateObject("Excel.Application")
If (Err.Number <> 0) Then
    On Error GoTo 0
    Wscript.Echo "Excel application not found."
    Wscript.Quit
End If

Set objExcel = CreateObject("Excel.Application")
objExcel.Visible = True
objExcel.DisplayAlerts = FALSE

Set objWorkbook = objExcel.Workbooks.Add
Set objWorksheet = objWorkbook.Worksheets(1)


'Creating Header for the Template excel
objWorksheet.Cells(1, 1).Value = "Server Name"
objWorkSheet.Cells(1, 2).Value = "Last Rebooted Date"
objWorkSheet.Cells(1, 3).Value = "Time"

strDate= Replace(Date,"/","-")
strTime= Replace(Time,":","-")
strSavefile = "C:\LastReboot_" & strDate & " " & strTime & ".xls"

x = 2

Do
       strComputer = objFile.ReadLine
       objWorksheet.cells(x,1).value = strComputer

Set objWMIService = GetObject("winmgmts:\\" & strComputer & "\root\cimv2")
Set colOperatingSystems = objWMIService.ExecQuery("Select * from Win32_OperatingSystem")
For Each objOS in colOperatingSystems
    Bootup = objOS.LastBootUpTime

NYear = Left(Bootup,4)
NMonth = Mid(Bootup,5, 2)
NDate = Mid(Bootup,7, 2)
Nhr= Mid(Bootup,9, 2)
Nmin = Mid(Bootup,11, 2)
Nsec= Mid(Bootup,13, 2)


objWorksheet.cells(x,2).value = (NMonth & "/"& NDate & "/" & NYear)
objWorksheet.cells(x,3).value = (Nhr & ":" & Nmin & ":" & Nsec)


Next
 x = x+1

 Loop Until objFile.AtEndOfStream=True

Set objrange = objWorksheet.Usedrange
objrange.entirecolumn.autofit()

objworkbook.SaveAs strSavefile

WScript.Echo "Excel file has been saved in C:\LastReboot_" & strDate & " " & strTime & ".xls"

objExcel.Application.Quit

Set objExcel = Nothing
Set objworkbook = Nothing
Set objworksheet = Nothing
Set objfile = Nothing

' End of script

17 comments:

  1. Can you kindly modify this script to give uptime in terms of days, hours instead of date

    ReplyDelete
  2. I'm getting an Expected end of statement

    ReplyDelete
  3. Laptop rentals are not just for experts. The best places that rent laptops will train you to use them for your specific purposes.
    http://www.showboxdownloadsapp.com/

    ReplyDelete
  4. When a computer is new it always seems to run faster and boot up quicker than your old computer. The applications and games seem to run without any slow down and when you get on the internet the pages load instantly on the screen, and you can quickly surf from one website to another.check it out

    ReplyDelete
  5. Great article with excellent idea!Thank you for such a valuable article. I really appreciate for this great information.. Learn more

    ReplyDelete
  6. This is extremely fascinating substance! I have completely delighted in perusing your focuses and have reached the conclusion that you are right about a hefty portion of them. You are extraordinary.  scopri di piu

    ReplyDelete
  7. This is really great work. Thank you for sharing such a good and useful information here in the blog for students.  Klick für mehr

    ReplyDelete
  8. I know your expertise on this. I must say we should have an online discussion on this. Writing only comments will close the discussion straight away! And will restrict the benefits from this information. mejoresvpn.com

    ReplyDelete
  9. The CRT monitor is the standard bulky and heavy monitor which many businesses still use today and they operate in a fairly similar manner to a TV. More 240hz monitor, Click here

    ReplyDelete
  10. That appears to be excellent however i am still not too sure that I like it. At any rate will look far more into it and decide personally! https://privacyonline.com.br

    ReplyDelete
  11. But that is enough with the history, it is now time to move onto the actual computer building process from start to finish. 10 Best Computers For College Student in 2019

    ReplyDelete
  12. Over the years it is how I learned most of what I do today, trial and error. One something goes wrong, there is always a way to fix it, and sometimes it just takes some patience and research to figure out a way to fix the problem.reset windows 10 password

    ReplyDelete
  13. If you have too many shortcuts displayed on the desktop then it will slow down the computer. This is another answer to your question: why is my computer running so slow and how to speed up computer.Best all in one computer: Definitive Buying Guide

    ReplyDelete
  14. Especially true during the times of the industrialization era and great world war where the need for such arose. How a computer behaves is what's in a library of a computer.Best Computer For College Student: expert's advice

    ReplyDelete
  15. At the very least, I don't want to throw it away. All used laptops have value to someone. top laptops

    ReplyDelete
  16. I would like to say that this blog really convinced me to do it! Thanks, very good post. hygienic monitor

    ReplyDelete
  17. There are potential problems that must be overcome when planning for technological integration. good site to check

    ReplyDelete