How To Get the System Uptime

There are many ways to obtain the system uptime from Windows GUI.

Just to list a couple:

  • Task Manager, Performance, Up Time. 
  • From the command prompt using the command prompt systeminfo ( system boot time).

But why don’t use Powershell or BaSH?

POWERSHELL

If you are using PowerShell version later than 5.1


BASH

The result looks similar, but what if we want to get from PowerShell just the uptime instead the last boot up time?

The New-TimeSpan cmdlet will help us to achieve what we really want:

Or in a one-liner

2 Replies to “How To Get the System Uptime”

  1. I think that you meant to omit line 1. Line 2 $now should be $today. You can do, uptime, with a one liner, in PowerShell, as well without the variables. New-TimeSpan -Start (Get-CimInstance -ClassName win32_operatingsystem).LastBootUpTime -End (Get-Date)

    1. Hi Micheal,
      Thanks for your comment and for adding another way to get with a oneliner the uptime and for finding an error.
      Regards

Leave a Reply

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

This site uses Akismet to reduce spam. Learn how your comment data is processed.