' 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
' 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
Can you kindly modify this script to give uptime in terms of days, hours instead of date
ReplyDeleteI'm getting an Expected end of statement
ReplyDeleteLaptop rentals are not just for experts. The best places that rent laptops will train you to use them for your specific purposes.
ReplyDeletehttp://www.showboxdownloadsapp.com/
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
ReplyDeleteGreat article with excellent idea!Thank you for such a valuable article. I really appreciate for this great information.. Learn more
ReplyDeleteThis 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
ReplyDeleteThis is really great work. Thank you for sharing such a good and useful information here in the blog for students. Klick für mehr
ReplyDeleteI 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
ReplyDeleteThe 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
ReplyDeleteThat 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
ReplyDeleteBut 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
ReplyDeleteOver 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
ReplyDeleteIf 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
ReplyDeleteEspecially 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
ReplyDeleteAt the very least, I don't want to throw it away. All used laptops have value to someone. top laptops
ReplyDeleteI would like to say that this blog really convinced me to do it! Thanks, very good post. hygienic monitor
ReplyDeleteThere are potential problems that must be overcome when planning for technological integration. good site to check
ReplyDelete