Check Windows Host Uptime with PowerShell

PowerADM.com / Windows / Windows 10 / Check Windows Host Uptime with PowerShell

In this article, we’re going to show you how to find out how much time your computer has been up since the last time Windows was started (uptime).

The easiest way to find out when Windows last booted up is to run the following command:

systeminfo | FIND "System Boot Time"

System Boot Time: 3/11/2023, 11:58:45 AM

systeminfo | FIND "System Boot Time"

This also gives the last boot time:

net statistics workstation

You can use the following PowerShell script to obtain not only the boot date, but also the time of continuous operation since the last boot:

$WinOS = Get-WmiObject Win32_OperatingSystem
write-host $WinOS.LastBootUpTime
(Get-Date)-$WinOS.ConvertToDateTime($WinOS.LastBootUpTime)

In this example, the Windows host has been running for 26 days without rebooting.

PowerShell: get Windows uptime

In this example, the Get-WmiObject cmdlet allows you to access the Win32_OperatingSystem class.

In PowerShell Core, you must use Get-CimInstance instead of the Get-WmiObject cmdlet:

Get-CimInstance -ClassName win32_operatingsystem -ComputerName localhost| select csname, lastbootuptime

or

(get-date) - (gcim Win32_OperatingSystem).LastBootUpTime

In addition, a new Get-Uptime cmdlet is available in PowerShell Core 6.x and 7.x. This cmdlet prints the uptime immediately (calculate the TimeSpan between the current time and the time when Windows was last started.):

Get-Uptime
Get-Uptime -Since

Get-Uptime cmdlet: eturns the time elapsed since the last boot of the operating system

You can find out the uptime of a remote computer from the command line.

You can connect to a remote computer via systeminfo and get BootTime:

SystemInfo /s appsrv01 | find "Boot Time:"

Or use CIM to find out the uptime of a remote computer.:

(Get-Date) - (Get-CimInstance Win32_OperatingSystem -ComputerName appsrv01).LastBootupTime

You can also use PowerShell to check the startup time of multiple remote Windows hosts at once (server names are separated by commas):

Get-CimInstance win32_operatingsystem -computerName server1,server2,server3  | select csname,LastBootUpTime
Leave a Reply

Your email address will not be published. Required fields are marked *