Moorfox

PowerShell automations · 2026-08-01

PowerShell: get the real last boot time and uptime

The script

Read LastBootUpTime from Win32_OperatingSystem. Note that with Fast Startup enabled, a shutdown and power-on is a resume, not a boot, so a machine can show weeks of uptime while its user insists they turn it off every night. Only a restart resets the counter.

$os = Get-CimInstance Win32_OperatingSystem
[PSCustomObject]@{
  LastBoot = $os.LastBootUpTime
  Uptime   = (Get-Date) - $os.LastBootUpTime
}

Notes before you run it

  • "I shut it down every night" and an uptime of 40 days are both true when Fast Startup is on. shutdown /s hibernates the kernel; shutdown /r actually reboots.
  • Pending-update problems and slow machines that a restart would fix hide behind this: check uptime before believing a machine has recently rebooted.
  • Disable Fast Startup fleet-wide with the registry value HiberbootEnabled = 0 under HKLM:\SYSTEM\CurrentControlSet\Control\Session Manager\Power if you want shutdowns to mean shutdowns.

Run it on every machine, not one at a time.

Save any of these as a command in Moorfox and run it on a machine in one click, output and exit code captured, with no PSRemoting or WinRM setup. The agent runs it locally and reports back, even over the internet.

Request an invite