4

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.

4
  • And why is LastBootUpTime not what you want? It's exactly "their as reboot time". Commented Sep 16, 2015 at 12:11
  • It's exactly what i want but i get something like this: csname lastbootuptime ------ -------------- LC006909 20150916141135.109999+330 Commented Sep 16, 2015 at 12:20
  • I need a normal time output Commented Sep 16, 2015 at 12:20
  • If 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). Commented Sep 16, 2015 at 13:35

4 Answers 4

4

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

0
4

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)}} 

Link

1

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)

2
  • I 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. Commented Sep 16, 2015 at 12:31
  • change it to systeminfo /s $computerName |find /i "boot time" Commented Sep 16, 2015 at 13:35
1

I always use

systeminfo | find "Time" 

which outputs

System Boot Time: 16/09/2015, 08:41:28 Time Zone: (UTC) Dublin, Edinburgh, Lisbon, London

You must log in to answer this question.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.