Skip to content

Instantly share code, notes, and snippets.

@mkorthof
Created August 24, 2017 12:39
Show Gist options
  • Save mkorthof/35cb3b3137942c44336180e5edd07975 to your computer and use it in GitHub Desktop.
Save mkorthof/35cb3b3137942c44336180e5edd07975 to your computer and use it in GitHub Desktop.
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