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

VMware vCenter: user@vsphere.local password expired - Authentication Failure

SSO log file: C:\ProgramData\VMware\vCenterServer\logs\sso\vmware-sts-idmd.log [2017-10-15T12:19:28.148+07:00 vsphere.local        e18baecc-2ce5-479a-adec-1bcbef603cdb ERROR] [IdentityManager] Failed to authenticate principal [tuyendq@vsphere.local]. User password expired. [2017-10-15T12:19:28.148+07:00 vsphere.local        e18baecc-2ce5-479a-adec-1bcbef603cdb INFO ] [IdentityManager] Authentication failed for user [tuyendq@vsphere.local] in tenant [vsphere.local] in [15] milliseconds with provider [vsphere.local] of type [com.vmware.identity.idm.server.provider.vmwdirectory.VMwareDirectoryProvider] [2017-10-15T12:19:28.148+07:00 vsphere.local        e18baecc-2ce5-479a-adec-1bcbef603cdb ERROR] [ServerUtils] Exception 'com.vmware.identity.idm.PasswordExpiredException: User account expired: {Name: tuyendq, Domain: vsphere.local}' com.vmware.identity.idm.PasswordExpiredException: User account expired: {Name: tuyendq, D...

Linux command: grep - Global Regular Expression Print

grep command grep, egrep, fgrep, rgrep - print lines matching a pattern

Windows Command: arp - Address Resolution Protocol

Notes from daily work situation. While troubleshooting HSRP, I need to delete arp table on my computer. arp -d * Take a look at other options with arp command: C:\Users\Administrator>arp /? Displays and modifies the IP-to-Physical address translation tables used by address resolution protocol (ARP). ARP -s inet_addr eth_addr [if_addr] ARP -d inet_addr [if_addr] ARP -a [inet_addr] [-N if_addr] [-v] -a Displays current ARP entries by interrogating the current protocol data. If inet_addr is specified, the IP and Physical addresses for only the specified computer are displayed. If more than one network interface uses ARP, entries for each ARP table are displayed. -g Same as -a. -v Displays current ARP entries in verbose mode. All invalid entries and entries on the loop-back interface will be shown. inet_addr Specifies an internet address. -N if_a...