Get System Uptime with PowerShell

Written by 9:24 am PowerShell

Get System Uptime with PowerShell

Sometimes you want to know how long your system is running. There are multiple ways to get the uptime of your system using the GUI or command line. PowerShell also offers a simple way to get the system uptime. If you are running PowerShell 6 or PowerShell 7 you can get the uptime with this simple cmdlet, which works on Windows, Linux, and macOS.

To get the system uptime on Windows, Linux, or macOS using PowerShell, you can use the Get-Uptime cmdlet.

Get-Uptime

Here how that looks on Ubuntu:

Get System Uptime on Linux using PowerShell

You can also use the “-Since” parameter to return a DateTime object representing the last time that the operating system was booted.

Get-Uptime PowerShell cmdlet with -since parameter

If you are running Windows PowerShell 5 or older, you can use the CIM Instance method and the Win32_OperatingSystem class. The Win32_OperatingSystem class has a LastBootupTime property which shows the time when the computer was rebooted.

Get-CimInstance -ClassName Win32_OperatingSystem | Select LastBootUpTime

I hope that quick PowerShell post gives you an overview of how you can get the system uptime on Windows, Linux, and macOS using PowerShell. If you have any questions feel free to leave a comment. If you want to know more about how you can install and update to PowerShell 7, check out my blog post, you can also learn what is new in PowerShell 7 right here.

You can also learn about PowerShell remoting between Windows, Linux, and macOS using PowerShell remoting over SSH.

Tags: , , , , , , , , , , , , Last modified: March 11, 2021
Close