Uptime of the server with PowerShell

Hi peoples.

This morning I had to check the Uptime of the server, and I must admit, I have totally forgot how to check the uptime of the server hehe…

Nevertheless, I have managed to find the command and check the uptime of the server.

This post is going to be really short, as there is only one tiny command which you have to run in order to check the uptime of the server.

I’m gonna show you how to do it in PowerShell 3.0, 2.0, and 1.0 (1.0 and 2.0 being the same).

Also check: ADDING A STATIC ROUTE

I am logged on my Windows Server 2012 right now at the moment, so lets check the version first by opening up PowerShell console and typing: $PSversionTable.psversion.major

Uptime of the server - PS version 3

As you may see, on Windows Server 2012, we are using Powershell version 3.

For PowerShell version 3, use the Get-CimInstance command, and select the LastBootUptime property from the Win32_OperatingSystem WMI class:

Get-CimInstance -ClassName win32_operatingsystem | select csname, lastbootuptime

Uptime of the server - Last Boot Uptime PS 3

For PowerShell version 1.0, and 2.0, we will use a little bit different command. We will use Get-WmiObject command, and then translate  the returned date to a readable format:

Get-WmiObject win32_operatingsystem | select csname, @{LABEL='LastBootUpTime' ;EXPRESSION={$_.ConverttoDateTime($_.lastbootuptime)}}

Uptime of the server - PS version 2

 

Uptime of the server - Last Boot Uptime PS 2

Post Navigation