mirror of
https://github.com/fleschutz/PowerShell.git
synced 2025-04-24 02:48:17 +02:00
Update check-swap-space.ps1
This commit is contained in:
parent
7b6f2b7cc2
commit
e192342523
@ -7,7 +7,7 @@
|
|||||||
Specifies the minimum level (10 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 of 1856 GB left.
|
✅ Swap space uses 63 GB of 1856 GB.
|
||||||
.LINK
|
.LINK
|
||||||
https://github.com/fleschutz/PowerShell
|
https://github.com/fleschutz/PowerShell
|
||||||
.NOTES
|
.NOTES
|
||||||
@ -17,6 +17,7 @@
|
|||||||
param([int]$MinLevel = 10) # minimum level in GB
|
param([int]$MinLevel = 10) # minimum level in GB
|
||||||
|
|
||||||
try {
|
try {
|
||||||
|
[int]$Total = [int]$Used = [int]$Free = 0
|
||||||
if ($IsLinux) {
|
if ($IsLinux) {
|
||||||
$Result = $(free --mega | grep Swap:)
|
$Result = $(free --mega | grep Swap:)
|
||||||
[int]$Total = $Result.subString(5,14)
|
[int]$Total = $Result.subString(5,14)
|
||||||
@ -25,18 +26,20 @@ try {
|
|||||||
} else {
|
} else {
|
||||||
$Items = Get-WmiObject -class "Win32_PageFileUsage" -namespace "root\CIMV2" -computername localhost
|
$Items = Get-WmiObject -class "Win32_PageFileUsage" -namespace "root\CIMV2" -computername localhost
|
||||||
foreach ($Item in $Items) {
|
foreach ($Item in $Items) {
|
||||||
[int]$Total = $Item.AllocatedBaseSize
|
$Total = $Item.AllocatedBaseSize
|
||||||
[int]$Used = $Item.CurrentUsage
|
$Used = $Item.CurrentUsage
|
||||||
[int]$Free = ($Total - $Used)
|
$Free = ($Total - $Used)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if ($Free -ge $MinLevel) {
|
if ($Total -eq 0) {
|
||||||
"✅ Swap space has $Free GB of $Total GB left."
|
|
||||||
} elseif ($Total -gt 0) {
|
|
||||||
"⚠️ Swap space has only $Free GB of $Total GB left to use!"
|
|
||||||
} else {
|
|
||||||
"⚠️ No swap space!"
|
"⚠️ No swap space!"
|
||||||
|
} elseif ($Free -lt $MinLevel) {
|
||||||
|
"⚠️ Swap space has only $Free GB of $Total GB left to use!"
|
||||||
|
} elseif ($Used -lt $Free) {
|
||||||
|
"✅ Swap space uses $Used GB of $Total GB."
|
||||||
|
} else {
|
||||||
|
"✅ Swap space has $Free GB of $Total GB left."
|
||||||
}
|
}
|
||||||
exit 0 # success
|
exit 0 # success
|
||||||
} catch {
|
} catch {
|
||||||
|
Loading…
Reference in New Issue
Block a user