To get the last boot time with PowerShell on Windows, run (Get-CimInstance -ClassName Win32_OperatingSystem).LastBootUpTime. Microsoft documents LastBootUpTime as the "date and time the operating system was last restarted", and Get-CimInstance returns it as a normal date and time you can compare and sort. To get uptime, subtract that value from the current time. In PowerShell 6.0 and later you can also use Get-Uptime. This guide covers both methods, why the two can differ slightly, how Windows Fast Startup affects the result, and a read-only script that reports last boot time across many computers.
Get the last boot time with PowerShell and Win32_OperatingSystem
The Win32_OperatingSystem WMI class "represents a Windows-based operating system installed on a computer". It has been available since Windows Vista and Windows Server 2008, and it works the same way in Windows PowerShell 5.1 and PowerShell 7 through Get-CimInstance:
# Last boot time of this computer
(Get-CimInstance -ClassName Win32_OperatingSystem).LastBootUpTime
# With the computer name, for a readable one-line result
Get-CimInstance -ClassName Win32_OperatingSystem |
Select-Object CSName, LastBootUpTime
The property is read-only, so querying it never changes anything on the computer. Older scripts often use Get-WmiObject for the same query. That cmdlet returns the date as a raw WMI string such as 20261118063015.500000+060, which then needs converting; Get-CimInstance gives you a date object directly, and it is the cmdlet that is available in PowerShell 7.
Calculate uptime from LastBootUpTime
Uptime is simply the time elapsed since the last boot. Subtracting one date from another in PowerShell produces a TimeSpan, which has Days, Hours and TotalDays properties:
$os = Get-CimInstance -ClassName Win32_OperatingSystem
$uptime = (Get-Date) - $os.LastBootUpTime
"Last boot: {0}" -f $os.LastBootUpTime
"Uptime: {0} days, {1} hours, {2} minutes" -f $uptime.Days, $uptime.Hours, $uptime.Minutes
Use TotalDays (a decimal number) when you want to filter or sort, for example to find computers that have been running longer than a set number of days.
Use Get-Uptime in PowerShell 7
PowerShell 6.0 introduced Get-Uptime, which "returns the time elapsed since the last boot of the operating system". By default it returns a TimeSpan. With the -Since switch it returns a DateTime for the last boot instead:
# Time since last boot (TimeSpan)
Get-Uptime
# Date and time of the last boot (DateTime)
Get-Uptime -Since
Two limits are worth knowing. Get-Uptime is not part of Windows PowerShell 5.1, which is still the version built into Windows, so a script that must run everywhere should use Win32_OperatingSystem. And it has no -ComputerName parameter; it only reads the computer it runs on.
Why Get-Uptime and LastBootUpTime can differ
Microsoft's notes for Get-Uptime explain that it "uses a high resolution timer to calculate the uptime", counting ticks since the system started. As a result, they say, the reported uptime "may differ slightly from other methods of calculating system uptime, such as the LastBootUpTime property of the Win32_OperatingSystem class". A gap of a few seconds between the two is expected and not a sign of a problem. Pick one method and use it consistently in reports.
Last boot time tells you when a computer restarted, not why. To see whether a restart was planned (event 1074) or unexpected (events 41 and 6008), query the System log with our guide to Get-WinEvent FilterHashtable filters.
Fast Startup: why a shutdown may not look like a reboot
A common surprise is a laptop that the user shuts down every evening but that reports days or weeks of uptime. Windows Fast Startup is the first thing to check. According to Microsoft's troubleshooting article on Fast Startup:
- Fast Startup is enabled by default in Windows.
- During a Fast Startup shutdown, "the kernel session is not closed, but it is hibernated": Windows saves the kernel session and device drivers to the hibernation file (
hiberfil.sys) instead of closing them. - "The Fast Startup setting doesn't apply to Restart." A restart continues to perform a full boot cycle.
- Full shutdown is the default when you use
Shutdown.exe, for exampleShutdown /s /t 0.
In practice, this means a "shut down and power on" cycle is not the same as a full boot, so it may not reset the uptime you see. When you need a clean boot, such as after installing updates or a driver, ask for a Restart and then confirm it by checking that LastBootUpTime has moved forward. Microsoft also states that disabling Fast Startup is not recommended, so treat it as something to account for in your checks rather than something to switch off across the fleet.
Check last boot time on remote computers
When you give Get-CimInstance a -ComputerName, Microsoft's documentation says it "creates a temporary session to the specified computer using the WsMan protocol" (WinRM). For several queries against the same computers, it recommends connecting with a CIM session for better performance. The script below reads last boot time and uptime from a list of computers and lists the ones that didn't answer:
$computers = 'PC-01', 'PC-02', 'SRV-APP01'
$sessions = New-CimSession -ComputerName $computers -ErrorAction SilentlyContinue
$report = Get-CimInstance -CimSession $sessions -ClassName Win32_OperatingSystem `
-Property CSName, LastBootUpTime |
Select-Object PSComputerName, LastBootUpTime,
@{ Name = 'UptimeDays'; Expression = { [math]::Round(((Get-Date) - $_.LastBootUpTime).TotalDays, 1) } }
# Longest uptime first
$report | Sort-Object UptimeDays -Descending | Format-Table -AutoSize
# Computers that returned nothing (not reachable over WinRM, or access denied)
$computers | Where-Object { $_ -notin $report.PSComputerName }
$sessions | Remove-CimSession
-Property asks only for the values the report needs, which Microsoft notes reduces the size of the object returned "either in memory or over the network". Review the last list by hand: a computer missing from the report has not been checked, and you can't assume when it last restarted.
To flag computers that haven't restarted recently, filter on the number. The 14-day threshold below is only an example; choose one that matches your own patching and maintenance schedule:
$report | Where-Object UptimeDays -gt 14
This approach depends on WinRM being enabled and reachable on every target, with an account that has permission on it. That is straightforward on a domain network and harder for laptops at home or devices across several sites. Our guide to PowerShell remote management without RDP compares WinRM, SSH and agent-based options.
Checking uptime through an RMM agent
With an agent-based tool, the command goes to an installed agent instead of an inbound WinRM connection. EclipseRMM's PowerShell RMM lists Get-CimInstance Win32_OperatingSystem among its example read-only diagnostics: you run authorized PowerShell on an enrolled Windows device and review the output, errors and completion status in the portal. A few points from the product pages apply directly to boot time checks:
- The EclipseRMM Windows agent runs as a service with automatic startup and reconnects after temporary outages, so a device that has just restarted comes back under its existing identity once it has network access again.
- The service runs as LocalSystem, so authorized commands run with high privileges. Keep to read-only checks like the ones above unless you intend to make a change, and review each command before submitting it.
- A disconnected device cannot be assumed to have run a request. If a device is showing as Offline, read what Online, Offline and last seen mean before drawing conclusions about whether it restarted.
Boot time is one of several quick health checks worth running together. See how to check service status with PowerShell and how to check disk space with PowerShell for the same multi-computer pattern, and our list of safe first PowerShell commands for more read-only checks.
FAQ
What is the PowerShell command for last boot time?
(Get-CimInstance -ClassName Win32_OperatingSystem).LastBootUpTime works in Windows PowerShell 5.1 and PowerShell 7. In PowerShell 6.0 and later, Get-Uptime -Since returns the same information for the local computer.
How do I see uptime in days?
Subtract the last boot time from the current time and read the Days or TotalDays property: ((Get-Date) - (Get-CimInstance Win32_OperatingSystem).LastBootUpTime).TotalDays. In PowerShell 7, (Get-Uptime).TotalDays gives the same kind of value.
Why didn't uptime reset after I shut the computer down?
With Fast Startup, which Microsoft says is enabled by default, a shutdown hibernates the kernel session rather than closing it. Restart isn't affected by the Fast Startup setting, so use Restart when you need a full boot, then confirm that LastBootUpTime changed.
Does checking last boot time change anything?
No. LastBootUpTime is a read-only property and Get-Uptime only reads a timer. Restarting a computer is a separate action; schedule it with the user and confirm it afterwards with the same check.