Update check-swap-space.ps1

This commit is contained in:
Markus Fleschutz 2022-10-09 19:27:14 +02:00
parent 107b807e22
commit 357a6f2fbb

View File

@ -4,17 +4,17 @@
.DESCRIPTION .DESCRIPTION
This PowerShell script checks the free swap space. This PowerShell script checks the free swap space.
.PARAMETER MinLevel .PARAMETER MinLevel
Specifies the minimum level (50 GB by default) Specifies the minimum level (10 GB by default)
.EXAMPLE .EXAMPLE
PS> ./check-swap-space PS> ./check-swap-space
Swap space has 1826 GB left (1856 GB total) Swap space has 1826 GB left, 1856 GB total.
.LINK .LINK
https://github.com/fleschutz/PowerShell https://github.com/fleschutz/PowerShell
.NOTES .NOTES
Author: Markus Fleschutz | License: CC0 Author: Markus Fleschutz | License: CC0
#> #>
param([int]$MinLevel = 50) # minimum level in GB param([int]$MinLevel = 10) # minimum level in GB
try { try {
if ($IsLinux) { if ($IsLinux) {
@ -32,13 +32,12 @@ try {
} }
if ($Total -eq "0") { if ($Total -eq "0") {
$Reply = "No swap space configured!" "⚠️ No swap space configured."
} elseif ($Free -lt $MinLevel) { } elseif ($Free -lt $MinLevel) {
$Reply = "Swap space has only $Free GB left to use! ($Used of $Total GB used, minimum is $MinLevel GB)" "⚠️ Swap space has only $Free GB left, $Total GB total!"
} else { } else {
$Reply = "✅ Swap space has $Free GB left, $Total GB total." "✅ Swap space has $Free GB left, $Total GB total."
} }
"$Reply"
exit 0 # success exit 0 # success
} catch { } catch {
"⚠️ Error in line $($_.InvocationInfo.ScriptLineNumber): $($Error[0])" "⚠️ Error in line $($_.InvocationInfo.ScriptLineNumber): $($Error[0])"