PowerTip: How Long Has My Computer Been Running?

Summary: Learn a one-liner Windows PowerShell command to see how long a computer has run.

Hey, Scripting Guy! Question How can I use Windows PowerShell to find out how long my computer has been running
          since last boot up without writing a script?

Hey, Scripting Guy! Answer Use the Win32_OperatingSystem WMI class and the LastBootupTime property,
          and then subtract the value of the current date/time that comes from Get-Date:

(Get-Date) – (Get-CimInstance Win32_operatingSystem).lastbootuptime

Comments (4)

  1. Thank you very much for this simple and interesting article. Here the parameters for a remote session:
    (Get-Date) – (Get-CimInstance Win32_operatingSystem -CimSession pc10).lastbootuptime

  2. Dev says:

    For some reason, the script above says that my computer has been running for 8 consecutive days, while I turned it on about 20 minutes ago. It was powered off, not hibernated, so that’s not the issue. Any idea what may cause this?

  3. Berv Nuon says:

    Thank you for the command and for the explanation of it!

Skip to main content