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.

GregL
  • 9,870
Cranta Ionut
  • 179
  • 3
  • 4
  • 12

4 Answers4

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

Nixphoe
  • 4,624
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

GregL
  • 9,870
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)

bjoster
  • 5,241
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

Greg
  • 11