Skip to content

Instantly share code, notes, and snippets.

@mkorthof mkorthof/uptime.cmd
Created Aug 24, 2017

Embed
What would you like to do?
windows uptime
@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))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.