Script for getting last reboot timestamp (2008r2)
Solution 1
Nixphoe's answer is definitely correct, but I want to add on how to get lastbootuptime for the multiple computers (the output can also be redirected to a file if needed):
Get Last Boot Time for Multiple Machines
$compname = Get-Content -Path C:\computers.txt
foreach ($comp in $compname) {
Get-WmiObject win32_operatingsystem -ComputerName $comp| select CSName, @{LABEL='LastBootUpTime';EXPRESSION={$_.ConverttoDateTime($_.lastbootuptime)}}
}
C:\computers.txt
- put computer hostnames one in a row here
Solution 2
For me, systeminfo is really slow. If you have powershell 3, you should be able to use something like
Get-CimInstance -ComputerName $yourcomputerObj -ClassName win32_operatingsystem | select csname, lastbootuptime
or
Get-WmiObject win32_operatingsystem -ComputerName $yourcomputerObj | select csname, @{LABEL='LastBootUpTime';EXPRESSION={$_.ConverttoDateTime($_.lastbootuptime)}}
Solution 3
I always use
systeminfo | find "Time"
which outputs
System Boot Time: 16/09/2015, 08:41:28
Time Zone: (UTC) Dublin, Edinburgh, Lisbon, London
Solution 4
There are many ways to get the last boot time:
systeminfo | find /i "Boot Time"
would do the trick, for example (in human readable format). Be aware of different languages here, in germany for example you would have to grep for "Systemstartzeit".
You could also try (language independent) wmi:
wmic os get lastBootUpTime
which will give you the Boot time in reversed format (like 20150915100340.494919+120)
Related videos on Youtube
![Cranta Ionut](https://lh6.googleusercontent.com/-7FoyUuxf10c/AAAAAAAAAAI/AAAAAAAAAB4/49NgBdrPCfo/photo.jpg?sz=256)
Cranta Ionut
I work as a system admin in an IT services company. I started 6 months ago from scratch with no professional background. I heard of Stack Exchange sites for some time now and finally decided to a proud member of it.
Updated on September 18, 2022Comments
-
Cranta Ionut almost 2 years
I have a list of ad-integrated computers and I need a list of them with their last reboot time. I found some comands like
Get-WmiObject -ClassName win32_operatingsystem -ComputerName xxx | select csname, lastbootuptime
but it's not what I need. I would need a script because there are lots of computers.I have no experience with PowerShell, if someone could help me with some suggestions.
PS C:\Users\XxX> Get-wmiobject win32_operatingsystem -ComputerName LC006909 | select csname, @{label='LastRestart';expression={$_.ConverToDateTime($_.LastBootUpTime)}} csname LastRestart ------ ----------- LC006909
I get this output ... empty under LastRestart.
-
Mike Shepard almost 9 yearsAnd why is LastBootUpTime not what you want? It's exactly "their as reboot time".
-
Cranta Ionut almost 9 yearsIt's exactly what i want but i get something like this: csname lastbootuptime ------ -------------- LC006909 20150916141135.109999+330
-
Cranta Ionut almost 9 yearsI need a normal time output
-
GregL almost 9 yearsIf you're getting a string like
20150916141135.109999+330
, then it's easily parsable into a "normal time output". Just break out the characters into year (2015), month (09), day (16), hour (14), minutes (11), seconds (35), what I assume are milliseconds (109999) and GMT offset (+330).
-
-
Cranta Ionut almost 9 yearsI agree with you but I'm connected on a Domain Controller and need this information on hundreds of computers. A powershell script or command would be more useful.
-
Nixphoe almost 9 yearschange it to
systeminfo /s $computerName |find /i "boot time"