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

This commit is contained in:
Markus Fleschutz 2021-03-15 17:14:33 +01:00
parent 17d4943291
commit be123b5af8
2 changed files with 10 additions and 8 deletions

View File

@ -13,14 +13,16 @@ if ($Drive -eq "" ) {
}
try {
$FreeSpace = (get-psdrive $Drive)
[int]$FreeSpace = (($FreeSpace.free / 1024) / 1024) / 1024
$DriveDetails = (get-psdrive $Drive)
[int]$FreeSpace = (($DriveDetails.Free / 1024) / 1024) / 1024
[int]$InUse = (($DriveDetails.Used / 1024) / 1024) / 1024
[int]$Total = ($InUse + $FreeSpace)
if ($FreeSpace -lt $MinLevel) {
write-warning "Drive $Drive has only $FreeSpace GB free space left! (minimum is $MinLevel GB)"
write-warning "Drive $Drive has only $FreeSpace GB left to use! ($InUse GB out of $Total GB in use, minimum is $MinLevel GB)"
exit 1
}
write-host -foregroundColor green "OK - drive $Drive has $FreeSpace GB free space left (minimum is $MinLevel GB)"
write-host -foregroundColor green "OK - drive $Drive has $FreeSpace GB left to use ($InUse GB out of $Total GB in use, minimum is $MinLevel GB)"
exit 0
} catch {
write-error "ERROR: line $($_.InvocationInfo.ScriptLineNumber): $($Error[0])"

View File

@ -13,14 +13,14 @@ try {
foreach ($Item in $Items) {
$Total = $Item.AllocatedBaseSize
$Current = $Item.CurrentUsage
$FreeSpace = ($Total - $Current)
$InUse = $Item.CurrentUsage
$FreeSpace = ($Total - $InUse)
}
if ($FreeSpace -lt $MinLevel) {
write-warning "Swap space has only $FreeSpace GB left to use! ($Current GB out of $Total GB in use, minimum is $MinLevel GB)"
write-warning "Swap space has only $FreeSpace GB left to use! ($InUse GB out of $Total GB in use, minimum is $MinLevel GB)"
exit 1
}
write-host -foregroundColor green "OK - swap space has $FreeSpace GB left to use ($Current GB out of $Total GB in use, minimum is $MinLevel GB)"
write-host -foregroundColor green "OK - swap space has $FreeSpace GB left to use ($InUse GB out of $Total GB in use, minimum is $MinLevel GB)"
exit 0
} catch {
write-error "ERROR: line $($_.InvocationInfo.ScriptLineNumber): $($Error[0])"