revlis.nl
Stash of notes about OSS, OSes, virtualization, dev hobby projects &c
August 23, 2017 — 14:07
Author: silver Category: windows Comments: Off
How to find out Windows Uptime?
Using PowerShell:
powershell ((Get-Date) - (gcim Win32_OperatingSystem).LastBootUptime).ToString('g')
powershell ((Get-Date) - ([wmi]'').ConvertToDateTime((Get-WmiObject win32_operatingsystem).LastBootUpTime)).ToString("dd' days 'hh\:mm\:ss")
Also, I cobbled together this little script that looks like the Linux uptime cmd. It’s embedded in a batch file so for ease of running (https://blogs.msdn.microsoft.com/jaybaz_ms/2007/04/26/powershell-polyglot/ for more info). Gist: https://git.io/v5tx0.
@PowerShell -ExecutionPolicy RemoteSigned -Command Invoke-Expression $('$args=@(^&{$args} %*);'+[String]::Join(';',(Get-Content -LiteralPath '%~f0') -notmatch '^^@PowerShell.*EOF$')) & goto :EOF $d = Get-Date $upTime = (($d) - ([wmi]'').ConvertToDateTime((Get-WmiObject win32_operatingsystem).LastBootUpTime)).ToString("d' days, 'h\:mm") $ActiveUsers = @() foreach($User in (Get-WmiObject Win32_LoggedOnUser).Antecedent) { $ActiveUsers += $User.Substring($User.LastIndexOf('=') + 2, $User.Length - $User.LastIndexOf('=') -3) } $UserText = "$($ActiveUsers.Count) user" if ( $ActiveUsers.Count -gt 1 ) { $UserText += "s" } $TotalProcTime = (Get-Counter "\Processor(_total)\% Processor Time") | foreach {$_.CounterSamples[0].CookedValue} Write-Host -NoNewLine (" {0}, up {1}, {2}, total proctime: {3}%" -f $d.toString("HH:mm:ss"), $upTime, $UserText, [math]::Round($TotalProcTime,2))
Output looks like this:
C:\Users\silver>uptime 14:45:41, up 5 days, 20:15, 3 users, total proctime: 2,26%
GUI (Windows 10):
Task Manager (taskmgr
) > More details > Performance tab > CPU
Boot Time:
net stats <workstation/server>
systeminfo | findstr "System Boot Time"