Windows Server Uptime : With cmd And PowerShell

Windows

There are various ways to find the Windows Server Uptime :

Windows Server Uptime via PowerShell UPTIME script:

We can use below Windows Powershell custom script to provide server uptime information:

Function Get-Uptime {
 Param([Parameter(Mandatory = $True,
 ValueFromPipeLine = $False,
 Position = 0)]
 [Alias('')]
 [String]$ComputerName = "localhost"
 )
 $LastBoot = (Get-WmiObject -Class Win32_OperatingSystem `
 -computername $ComputerName).LastBootUpTime
 $sysuptime = (Get-Date) – `
 [System.Management.ManagementDateTimeconverter]::`
 ToDateTime($LastBoot)
 Write-Host -foregroundcolor cyan "($ComputerName) System uptime is:" `
 $sysuptime.days"days"$sysuptime.hours"hours"$sysuptime.minutes`
 "minutes"$sysuptime.seconds"seconds"
 }
 get-uptime localhost
 

Output:

PS C:\Users\Adam1> Function Get-Uptime {
>>  Param([Parameter(Mandatory = $True,
>>  ValueFromPipeLine = $False,
>>  Position = 0)]
>>  [Alias('')]
>>  [String]$ComputerName = "localhost"
>>  )
>>  $LastBoot = (Get-WmiObject -Class Win32_OperatingSystem `
>>  -computername $ComputerName).LastBootUpTime
>>  $sysuptime = (Get-Date) - `
>>  [System.Management.ManagementDateTimeconverter]::`
>>  ToDateTime($LastBoot)
>>  Write-Host -foregroundcolor cyan "($ComputerName) System uptime is:" `
>>  $sysuptime.days"days"$sysuptime.hours"hours"$sysuptime.minutes`
>>  "minutes"$sysuptime.seconds"seconds"
>>  }
>>  get-uptime localhost
(localhost) System uptime is: 5 days 1 hours 8 minutes 28 seconds

Alternatively there are ways to calculate the uptime:

Uptime Via SYSTEMINFO

With systeminfo command, we can get the boot time of the system.

C:\Users\Adam1>systeminfo

Host Name:                 ABNServer1
OS Name:                   Microsoft Windows server 2016
OS Version:                10.0.20041 N/A Build 20041
OS Manufacturer:           Microsoft Corporation
Registered Organization:   N/A
Product ID:                00123-12375-693422-ABCSW
Original Install Date:     29-02-2021, 15:23:23
System Boot Time:          08-05-2021, 13:53:58

Uptime via Get-Uptime (Powershell)

PS C:\Users\Adam1> Get-Uptime

cmdlet Get-Uptime at command pipeline position 1
Supply values for the following parameters:
ComputerName: ABNServer1
(ABNServer1) System uptime is: 5 days 1 hours 32 minutes 25 seconds

Uptime via last boot (Powershell)

Get-Uptime -Since

Saturday, May 8, 2021 2:34:56 PM