You can get the last boot time of the computer or remote computers using the PowerShell script. net stats, systeminfo, wmic (windows management instrumentation), and Get-WmiObject is used to get the last boot time of the computer.
In this article, we will discuss different ways to find the last boot time of a computer or multiple computers.
Get last boot time of computer using Get-CimInstance
You can use the PowerShell Get-CimInstance cmdlet to get the system last boot time.
Get-CimInstance -ClassName win32_operatingsystem | select csname, lastbootuptime
In the above PowerShell script example,
Get-CimInstance uses win32_operatingsystem class name to get system information and passes the information through the pipeline operator to the second command.
In the second command, it selects csname and lastbootuptime property and displays the last boot time of the local computer.
The output of the above script is as given below
PS C:\> Get-CimInstance -ClassName win32_operatingsystem | select csname, lastbootuptime
csname lastbootuptime
------ --------------
INCORP-EU-D101 21-10-2021 16:00:35
Find last reboot time of computer using net statistics
The net statistics command displays statistics about the system like bytes received, system errors, last boot time of computer, and total uptime of computer from last boot of computer.
net statistics workstation | select-string "Statistics"
In the above PowerShell script,
the net statistics command gets the last boot time of the computer.
The output of the above command is given below
PS C:\> net statistics workstation | select-string "Statistics"
Workstation Statistics for \\INCORP-EU-D101
Statistics since 21-10-2021 16:01:28
Get last boot time of computer using systemInfo
You can use the systeminfo command to get the last boot time of the computer.
systeminfo | Select-String "Host Name","System Boot Time"
The above command gets the last reboot time of the local computer and prints Host Name and System Boot Time on the terminal as given below
PS C:\> systeminfo | Select-String "Host Name","System Boot Time"
Host Name: INCORP-EU-D101
System Boot Time: 21-10-2021, 16:00:35
You can use the systeminfo command to get the last boot time of the remote computer using the below command
systeminfo /S "incorp-eu-D102" | Select-String "Host Name","System Boot Time"
In the above command,
systeminfo uses the /S parameter to specify the server name.
It returns the last boot time for the remote computer.
Get last boot time of computer using Get-WmiObject
You can use the PowerShell Get-WmiObject command to get the last boot time for your computer using the given below command
Get-WmiObject win32_operatingsystem | select csname, @{LABEL='LastBootUpTime';EXPRESSION={$_.ConverttoDateTime($_.lastbootuptime)}}
In the above PowerShell script,
The get-WmiObject command uses win32_operatingsystem class to get the computer name and lastbootuptime for the computer.
It returns the lastbootuptime in large integer format which needs to convert to a readable format.
The output of the above command is given below
PS C:\> Get-WmiObject win32_operatingsystem | select csname, @{LABEL='LastBootUpTime';EXPRESSION={$_.ConverttoDateTime($_.lastbootuptime)}}
csname LastBootUpTime
------ --------------
INCORP-EU-D101 21-10-2021 16:00:35
Check Last boot time of computer using wmic
You can use the wmic command to get the last boot time of the computer as given below
wmic OS get lastbootuptime
How to check windows reboot history?
You can use the Get-WmiObject cmdlet in PowerShell to check windows reboot history using event code 6005.
Use the given below command to get windows reboot history
Get-WmiObject Win32_NTLogEvent -filter "LogFile='System' and EventCode=6005" | Select ComputerName, EventCode, @{LABEL='TimeWritten';EXPRESSION={$_.ConverttoDateTime($_.TimeWritten)}}
In the above PowerShell script,
Get-WmiObject cmdlet in PowerShell uses Win32_NTLogEvent to filter events by eventcode equal to 6005 and returns windows computer reboot history.
Cool Tip: How to get an activation key for Windows in PowerShell!
Conclusion
I hope the above article on how to get the last boot time of local computer and reboot time of remote computer using different ways in PowerShell is helpful to you.
We have learned in the above article how to get the reboot history of a computer using the Get-WmiObject cmdlet in PowerShell.
You can find more topics about PowerShell Active Directory commands and PowerShell basics on the ShellGeek home page.