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

IIS: Delete cached files on server running IIS

Delete cached files on server running IIS When changing css, javascript files, check to delete if IIS still caches old files in the default folder C:\inetpub\temp\IIS Temporary Compressed Files\<sitename>\$^_gzip_D^\ Apply to: IIS 8.5

Linux command: du - disk usage

Where have all my storage gone? du summarize disk usage of the set of FILEs, recursively for directories.

ManageEngine ServiceDesk Plus - Reset password

Let's reset the default administrator's password to 'admin'