Skip to main content

Powershell: Get-Uptime


Start with Powershell 6, there is Get-Uptime cmdlet to tell how long the system running.

Example with Powershell Core on RHEL 7.6

[tuyendq@rhel1 ~]$ pwsh
PowerShell 6.2.0
Copyright (c) Microsoft Corporation. All rights reserved.

https://aka.ms/pscore6-docs
Type 'help' to get help.
PS /home/tuyendq> Get-Uptime -Since

Monday, December 31, 2018 10:42:03 PM
PS /home/tuyendq> Get-Uptime

Days              : 150
Hours             : 22
Minutes           : 14
Seconds           : 34
Milliseconds      : 0
Ticks             : 130400740000000
TotalDays         : 150.926782407407
TotalHours        : 3622.24277777778
TotalMinutes      : 217334.566666667
TotalSeconds      : 13040074
TotalMilliseconds : 13040074000


PS /home/tuyendq>

You will get error with Powershell version earlier than 6.0. Let's try with PSVersion 5.1.x on Windows 10

PS F:\Projects\lthwpowershell> $PSVersionTable

Name                           Value
----                           -----
PSVersion                      5.1.17763.503
PSEdition                      Desktop
PSCompatibleVersions           {1.0, 2.0, 3.0, 4.0...}
BuildVersion                   10.0.17763.503
CLRVersion                     4.0.30319.42000
WSManStackVersion              3.0
PSRemotingProtocolVersion      2.3
SerializationVersion           1.1.0.1


PS F:\Projects\lthwpowershell> Get-Uptime
Get-Uptime : The term 'Get-Uptime' is not recognized as the name of a cmdlet, function, script
file, or operable program. Check the spelling of the name, or if a path was included, verify
that the path is correct and try again.
At line:1 char:1
+ Get-Uptime
+ ~~~~~~~~~~
    + CategoryInfo          : ObjectNotFound: (Get-Uptime:String) [], CommandNotFoundException
    + FullyQualifiedErrorId : CommandNotFoundException

PS F:\Projects\lthwpowershell>

Popular posts from this blog

[MicrosoftVisualStudio]: Hiển thị số dòng lệnh

Hiển thị số dòng lệnh trong Microsoft Visual Studio Hiển thị số dòng trong Microsoft Visual Studio giúp tìm đến dòng lệnh gây ra lỗi. Nhấn Options Đánh dấu mục Line numbers ở phần Display Nhấn OK để lưu lại thiết lập.

Learn MATLAB

MATLAB is an abbreviation for MAT rix LAB oratory. Here is list of free online courses to learn MATLAB.

Hydra: Notes

Hydra v9.1 (c) 2020 by van Hauser/THC & David Maciejak - Please do not use in military or secret service organizations, or for illegal purposes (this is non-binding, these *** ignore laws and ethics anyway).