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

Fedora Workstation: Install snapd

[tuyen@g73jh ~]$ sudo dnf -y install snapd Last metadata expiration check: 0:20:17 ago on Tue 01 Oct 2019 11:31:30 AM +07. Dependencies resolved. ================================================================================ Package Architecture Version Repository Size ================================================================================ Installing: snapd x86_64 2.41-1.fc30 updates 17 M Installing dependencies: snap-confine x86_64 2.41-1.fc30 updates 2.8 M snapd-glib x86_64 1.49-1.fc30 updates 133 k snapd-selinux noarch 2.41-1.fc30 updates 234 k Installing weak dependencies: gnome-software-snap x86_64 3.32.4-2.fc30 updates 86 k Transaction Summary ================================================================================ Install 5 Packages Total download size...

Apache Airflow: Notes

Apache Airflow is used to programmatically author, schedule and monitor workflows.

[Powershell]: Get-Date and commonly used date format

Get-Date and commonly used date format in powershell PS C:\Users\Administrator> get-date Thursday, June 25, 2015 9:42:24 AM PS C:\Users\Administrator> $today = get-date PS C:\Users\Administrator> echo $today Thursday, June 25, 2015 9:43:21 AM PS C:\Users\Administrator> $todayshort = get-date -format yyMMdd PS C:\Users\Administrator> echo $todayshort 150625 PS C:\Users\Administrator> $todaylong = get-date -format yyyyMMdd PS C:\Users\Administrator> echo $todaylong 20150625 PS C:\Users\Administrator>