mirror of
https://github.com/fleschutz/PowerShell.git
synced 2025-05-29 14:40:57 +02:00
Update check-swap-space.ps1
This commit is contained in:
parent
3ec85bc048
commit
a7b8943e99
@ -16,6 +16,16 @@
|
|||||||
|
|
||||||
param([int]$MinLevel = 10) # minimum level in GB
|
param([int]$MinLevel = 10) # minimum level in GB
|
||||||
|
|
||||||
|
function GB2String { param([int64]$Bytes)
|
||||||
|
if ($Bytes -lt 1000) { return "$($Bytes)GB" }
|
||||||
|
$Bytes /= 1000
|
||||||
|
if ($Bytes -lt 1000) { return "$($Bytes)TB" }
|
||||||
|
$Bytes /= 1000
|
||||||
|
if ($Bytes -lt 1000) { return "$($Bytes)PB" }
|
||||||
|
$Bytes /= 1000
|
||||||
|
if ($Bytes -lt 1000) { return "$($Bytes)EB" }
|
||||||
|
}
|
||||||
|
|
||||||
try {
|
try {
|
||||||
[int]$Total = [int]$Used = [int]$Free = 0
|
[int]$Total = [int]$Used = [int]$Free = 0
|
||||||
if ($IsLinux) {
|
if ($IsLinux) {
|
||||||
@ -31,17 +41,16 @@ try {
|
|||||||
$Free = ($Total - $Used)
|
$Free = ($Total - $Used)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if ($Total -eq 0) {
|
if ($Total -eq 0) {
|
||||||
"⚠️ No swap space!"
|
"⚠️ No swap space!"
|
||||||
} elseif ($Free -lt $MinLevel) {
|
} elseif ($Free -lt $MinLevel) {
|
||||||
"⚠️ Swap space has only $Free GB of $Total GB left to use!"
|
"⚠️ Swap space has only $(GB2String $Free) of $(GB2String $Total) left to use!"
|
||||||
} elseif ($Used -eq 0) {
|
} elseif ($Used -eq 0) {
|
||||||
"✅ Swap space of $Total GB is unused."
|
"✅ Swap space of $(GB2String $Total) is unused."
|
||||||
} elseif ($Used -lt $Free) {
|
} elseif ($Used -lt $Free) {
|
||||||
"✅ Swap space uses $Used GB of $Total GB."
|
"✅ Swap space uses $(GB2String $Used) of $(GB2String $Total)."
|
||||||
} else {
|
} else {
|
||||||
"✅ Swap space has $Free GB of $Total GB left."
|
"✅ Swap space has $(GB2String $Free) of $(GB2String $Total) left."
|
||||||
}
|
}
|
||||||
exit 0 # success
|
exit 0 # success
|
||||||
} catch {
|
} catch {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user