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

This commit is contained in:
Markus Fleschutz 2023-08-16 08:12:18 +02:00
parent 355989f481
commit 6e02dba5da
2 changed files with 7 additions and 11 deletions

View File

@ -45,7 +45,7 @@ try {
if ($total -eq 0) { if ($total -eq 0) {
Write-Host "✅ Drive $name is empty" Write-Host "✅ Drive $name is empty"
} elseif ($free -eq 0) { } elseif ($free -eq 0) {
Write-Host "⚠️ Drive $name with $(Bytes2String $total) is 100% full" Write-Host "⚠️ Drive $name with $(Bytes2String $total) is full"
} elseif ($free -lt $minLevel) { } elseif ($free -lt $minLevel) {
Write-Host "⚠️ Drive $name with $(Bytes2String $total) is nearly full, $(Bytes2String $free) free" Write-Host "⚠️ Drive $name with $(Bytes2String $total) is nearly full, $(Bytes2String $free) free"
} else { } else {

View File

@ -3,18 +3,18 @@
Checks the swap space status Checks the swap space status
.DESCRIPTION .DESCRIPTION
This PowerShell script queries the status of the swap space and prints it. This PowerShell script queries the status of the swap space and prints it.
.PARAMETER MinLevel .PARAMETER minLevel
Specifies the minimum level (10 GB by default) Specifies the minimum level in GB (10 GB by default)
.EXAMPLE .EXAMPLE
PS> ./check-swap-space.ps1 PS> ./check-swap-space.ps1
1GB Swap space at 42%, 748MB free Swap space at 42% of 1GB, 748MB free
.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 = 10) # minimum level in GB param([int]$minLevel = 10)
function MB2String { param([int64]$Bytes) function MB2String { param([int64]$Bytes)
if ($Bytes -lt 1000) { return "$($Bytes)MB" } if ($Bytes -lt 1000) { return "$($Bytes)MB" }
@ -47,17 +47,13 @@ try {
Write-Output "⚠️ No swap space configured" Write-Output "⚠️ No swap space configured"
} elseif ($Free -eq 0) { } elseif ($Free -eq 0) {
Write-Output "⚠️ $(MB2String $Total) Swap space is full" Write-Output "⚠️ $(MB2String $Total) Swap space is full"
} elseif ($Free -lt $MinLevel) { } elseif ($Free -lt $minLevel) {
Write-Output "⚠️ $(MB2String $Total) Swap space is nearly full, only $(MB2String $Free) free" Write-Output "⚠️ $(MB2String $Total) Swap space is nearly full, only $(MB2String $Free) free"
} elseif ($Used -eq 0) { } elseif ($Used -eq 0) {
Write-Output "$(MB2String $Total) Swap space reserved" Write-Output "$(MB2String $Total) Swap space reserved"
} else { } else {
[int]$Percent = ($Used * 100) / $Total [int]$Percent = ($Used * 100) / $Total
if ($Percent -ge 90) { Write-Output "✅ Swap space at $Percent% of $(MB2String $Total), $(MB2String $Free) free"
Write-Output "$(MB2String $Total) Swap space is $Percent% full, only $(MB2String $Free) free"
} else {
Write-Output "$(MB2String $Total) Swap space at $Percent%, $(MB2String $Free) free"
}
} }
exit 0 # success exit 0 # success
} catch { } catch {