Update check-battery.ps1, check-drives.ps1, and check-swap-space.ps1

This commit is contained in:
Markus Fleschutz 2022-12-19 19:33:32 +01:00
parent 86463af566
commit c83f590247
3 changed files with 21 additions and 15 deletions

View File

@ -17,18 +17,20 @@ try {
} else {
Add-Type -Assembly System.Windows.Forms
$Details = [System.Windows.Forms.SystemInformation]::PowerStatus
if ($Details.BatteryChargeStatus -eq "NoSystemBattery") {
$BatteryStatus = "No battery"
} else {
[int]$Percent = 100*$Details.BatteryLifePercent
[int]$Remaining = $Details.BatteryLifeRemaining / 60
$BatteryStatus = "Battery $Percent%, $Remaining min left"
}
$Status = ""
switch ($Details.PowerLineStatus) {
"Online" { $PowerStatus = "plugged in to AC power" }
"Offline" { $PowerStatus = "AC power unplugged" }
"Online" { $Power = "AC powered" }
"Offline" { $Power = "No AC power" }
}
"$BatteryStatus, $PowerStatus"
if ($Details.BatteryChargeStatus -eq "NoSystemBattery") {
$Battery = "no system battery"
} else {
[int]$Percent = 100 * $Details.BatteryLifePercent
[int]$Remaining = $Details.BatteryLifeRemaining / 60
if ($Remaining -lt 30) { $Status = "⚠️" }
$Battery = "$Percent% battery life, $Remaining min. left"
}
"$Status $Power, $Battery"
}
exit 0 # success
} catch {

View File

@ -42,12 +42,14 @@ try {
if ($Total -eq 0) {
"✅ Drive $ID is empty"
} elseif ($Free -eq 0) {
"⚠️ Drive $ID with $(Bytes2String $Total) is full!"
} elseif ($Free -lt $MinLevel) {
"⚠️ Drive $ID has only $(Bytes2String $Free) of $(Bytes2String $Total) left to use!"
"⚠️ Drive $ID with $(Bytes2String $Total) is nearly full ($(Bytes2String $Free) free)!"
} elseif ($Used -lt $Free) {
"✅ Drive $ID uses $(Bytes2String $Used) of $(Bytes2String $Total)"
} else {
"✅ Drive $ID has $(Bytes2String $Free) free of $(Bytes2String $Total)"
"✅ Drive $ID has $(Bytes2String $Free) of $(Bytes2String $Total) free"
}
}
exit 0 # success

View File

@ -7,7 +7,7 @@
Specifies the minimum level (10 GB by default)
.EXAMPLE
PS> ./check-swap-space
Swap space uses 63 GB of 1856 GB.
Swap space uses 63GB of 1856GB
.LINK
https://github.com/fleschutz/PowerShell
.NOTES
@ -45,14 +45,16 @@ try {
}
if ($Total -eq 0) {
"⚠️ No swap space configured!"
} elseif ($Free -eq 0) {
"⚠️ Swap space of $(MB2String $Total) is full!"
} elseif ($Free -lt $MinLevel) {
"⚠️ Only $(MB2String $Free) of $(MB2String $Total) swap space left to use!"
"⚠️ Swap space of $(MB2String $Total) is nearly full ($(MB2String $Free) free)!"
} elseif ($Used -eq 0) {
"✅ Swap space with $(MB2String $Total) reserved"
} elseif ($Used -lt $Free) {
"✅ Swap space uses $(MB2String $Used) of $(MB2String $Total)"
} else {
"✅ Swap space has $(MB2String $Free) of $(MB2String $Total) left to use"
"✅ Swap space has $(MB2String $Free) of $(MB2String $Total) free"
}
exit 0 # success
} catch {