PowerShell for Windows Admins

Nov 23 2017   11:04AM GMT

PowerShell v6: #5 Get-Uptime

Richard Siddaway Richard Siddaway Profile: Richard Siddaway

Tags:
Powershell

One new feature of PowerShell v6 (its actually been available since alpha 13 but I’d missed it) is the Get-Uptime cmdlet

PS C:\scripts> Get-Uptime

Days              : 0
Hours             : 2
Minutes           : 57
Seconds           : 6
Milliseconds      : 0
Ticks             : 106260000000
TotalDays         : 0.122986111111111
TotalHours        : 2.95166666666667
TotalMinutes      : 177.1
TotalSeconds      : 10626
TotalMilliseconds : 10626000

You get a timespan object returned for the uptime.

If you want to get something similar in Windows PowerShell you need to access the Win32_OperatingSystem CIM class

PS> (Get-Date) - (Get-CimInstance -ClassName Win32_OperatingSystem | select -ExpandProperty LastBootUpTime)

Days              : 0
Hours             : 3
Minutes           : 7
Seconds           : 7
Milliseconds      : 850
Ticks             : 112278501750
TotalDays         : 0.129951969618056
TotalHours        : 3.11884727083333
TotalMinutes      : 187.13083625
TotalSeconds      : 11227.850175
TotalMilliseconds : 11227850.175

 

Ah! We’re back to the days of the PowerShell one liner – though to be accurate it should one pipeliner.

Remember that Windows 8, 8.1 and 10 will only reset LastBootUpTime on a restart. If you use Shutdown on the Start menu its effectively hibernating which explains why these versions of windows boot up so quickly.

 

 

 Comment on this Post

 
There was an error processing your information. Please try again later.
Thanks. We'll let you know when a new response is added.
Send me notifications when other members comment.

Forgot Password

No problem! Submit your e-mail address below. We'll send you an e-mail containing your password.

Your password has been sent to:

Share this item with your network: