Updated check-power.ps1 and check-swap-space.ps1

This commit is contained in:
Markus Fleschutz 2024-09-14 14:29:28 +02:00
parent ff9546b323
commit 5c34a983fe
2 changed files with 15 additions and 15 deletions

View File

@ -5,7 +5,7 @@
This PowerShell script queries the power status and prints it. This PowerShell script queries the power status and prints it.
.EXAMPLE .EXAMPLE
PS> ./check-power.ps1 PS> ./check-power.ps1
Battery at 9% with power scheme 'HP Optimized' - 54min remaining Battery 9% only with 54min remaining (power scheme is 'HP Optimized')
.LINK .LINK
https://github.com/fleschutz/PowerShell https://github.com/fleschutz/PowerShell
.NOTES .NOTES
@ -27,25 +27,25 @@ try {
if ($details.BatteryChargeStatus -eq "NoSystemBattery") { if ($details.BatteryChargeStatus -eq "NoSystemBattery") {
$reply = "✅ AC powered" $reply = "✅ AC powered"
} elseif ($percent -ge 95) { } elseif ($percent -ge 95) {
$reply = "✅ Battery nearly full ($percent%, power scheme '$powerScheme')" $reply = "✅ Battery nearly full ($percent%, power scheme is '$powerScheme')"
} else { } else {
$reply = "✅ Battery charging ($percent%, power scheme '$powerScheme')" $reply = "✅ Battery charging ($percent%, power scheme is '$powerScheme')"
} }
} else { # must be offline } else { # must be offline
if (($remaining -eq 0) -and ($percent -ge 60)) { if (($remaining -eq 0) -and ($percent -ge 60)) {
$reply = "✅ Battery $percent% full (power scheme '$powerScheme')" $reply = "✅ Battery $percent% full (power scheme is '$powerScheme')"
} elseif ($remaining -eq 0) { } elseif ($remaining -eq 0) {
$reply = "✅ Battery at $percent% (power scheme '$powerScheme')" $reply = "✅ Battery at $percent% (power scheme is '$powerScheme')"
} elseif ($remaining -le 5) { } elseif ($remaining -le 5) {
$reply = "⚠️ Battery at $percent% (power scheme '$powerScheme') - ONLY $($remaining)min remaining" $reply = "⚠️ Battery $percent% ONLY $($remaining)min remaining (power scheme is '$powerScheme')"
} elseif ($remaining -le 30) { } elseif ($remaining -le 30) {
$reply = "⚠️ Battery at $percent% (power scheme '$powerScheme') - only $($remaining)min remaining" $reply = "⚠️ Battery $percent% only $($remaining)min remaining (power scheme is '$powerScheme')"
} elseif ($percent -lt 10) { } elseif ($percent -lt 10) {
$reply = "⚠️ Battery at $percent% (power scheme '$powerScheme') - $($remaining)min remaining" $reply = "⚠️ Battery $percent% only with $($remaining)min remaining (power scheme is '$powerScheme') "
} elseif ($percent -ge 80) { } elseif ($percent -ge 90) {
$reply = "✅ Battery $percent% full (power scheme '$powerScheme') - $($remaining)min remaining" $reply = "✅ Battery $percent% full with $($remaining)min remaining (power scheme is '$powerScheme')"
} else { } else {
$reply = "✅ Battery at $percent% (power scheme '$powerScheme') - $($remaining)min remaining" $reply = "✅ Battery $percent% with $($remaining)min remaining (power scheme is '$powerScheme') "
} }
} }
} }

View File

@ -48,14 +48,14 @@ try {
if ($total -eq 0) { if ($total -eq 0) {
Write-Output "⚠️ No swap space configured" Write-Output "⚠️ No swap space configured"
} elseif ($free -eq 0) { } elseif ($free -eq 0) {
Write-Output "⚠️ Swap space is FULL ($(MB2String $total))" Write-Output "⚠️ Swap space is full ($(MB2String $total))"
} elseif ($free -lt $minLevel) { } elseif ($free -lt $minLevel) {
Write-Output "⚠️ Swap space has only $(MB2String $free) of $(MB2String $total) free" Write-Output "⚠️ Swap space has only $(MB2String $free) of $(MB2String $total) left"
} elseif ($used -lt 3) { } elseif ($used -lt 3) {
Write-Output "✅ Swap space unused - $(MB2String $free) available" Write-Output "✅ Swap space unused - $(MB2String $free) available"
} else { } else {
[int64]$percent = ($used * 100) / $total [int64]$percent = ($free * 100) / $total
Write-Output "✅ Swap space at $percent% of $(MB2String $total) - $(MB2String $free) free" Write-Output "✅ Swap space has $(MB2String $free) of $(MB2String $total) left ($percent%)"
} }
exit 0 # success exit 0 # success
} catch { } catch {