Skip to content

Instantly share code, notes, and snippets.

@raresteak
Created November 12, 2024 14:48
Show Gist options
  • Save raresteak/28dc2377e95a0f4b3c3bf4270c09f2bb to your computer and use it in GitHub Desktop.
Save raresteak/28dc2377e95a0f4b3c3bf4270c09f2bb to your computer and use it in GitHub Desktop.
Uptime command similiar to Unix uptime
# Similiar to unix command uptime
$bootTime = Get-CimInstance -ClassName win32_operatingsystem | Select-Object -ExpandProperty LastBootUpTime
$currentTime = Get-Date
$uptime = $currentTime - $bootTime
$days = $uptime.Days
$hours = $uptime.Hours
$minutes = $uptime.Minutes
$users = (quser).Count-1
if ( $users -lt 0 ) {
$users = 0
}
$load = get-wmiobject -class win32_processor | measure-object -property LoadPercentage -Average | select-object -expandproperty Average
Write-Output " $currentTime up $days days, ${hours}:${minutes}, $users user, load: $load"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment