Created
November 12, 2024 14:48
-
-
Save raresteak/28dc2377e95a0f4b3c3bf4270c09f2bb to your computer and use it in GitHub Desktop.
Uptime command similiar to Unix uptime
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# 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