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

This commit is contained in:
Markus Fleschutz
2022-11-06 22:06:55 +01:00
parent a7b8943e99
commit 26ad83c417
3 changed files with 30 additions and 12 deletions

View File

@ -15,23 +15,39 @@
param([int]$MinLevel = 10) # 10 GB minimum
function Bytes2String { param([int64]$Bytes)
if ($Bytes -lt 1000) { return "$Bytes bytes" }
$Bytes /= 1000
if ($Bytes -lt 1000) { return "$($Bytes)KB" }
$Bytes /= 1000
if ($Bytes -lt 1000) { return "$($Bytes)MB" }
$Bytes /= 1000
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 {
$Drives = Get-PSDrive -PSProvider FileSystem
foreach($Drive in $Drives) {
$ID = $Drive.Name
$Details = (Get-PSDrive $ID)
[int]$Free = $Details.Free / 1GB
[int]$Used = $Details.Used / 1GB
[int]$Total = ($Used + $Free)
[int64]$Free = $Details.Free
[int64]$Used = $Details.Used
[int64]$Total = ($Used + $Free)
if ($Total -eq 0) {
"✅ Drive $ID is empty."
} elseif ($Free -lt $MinLevel) {
"⚠️ Drive $ID has only $Free GB of $Total GB left to use!"
"⚠️ Drive $ID has only $(Bytes2String $Free) of $(Bytes2String $Total) left to use!"
} elseif ($Used -lt $Free) {
"✅ Drive $ID uses $Used GB of $Total GB."
"✅ Drive $ID uses $(Bytes2String $Used) of $(Bytes2String $Total)."
} else {
"✅ Drive $ID has $Free GB of $Total GB left."
"✅ Drive $ID has $(Bytes2String $Free) of $(Bytes2String $Total) left."
}
}
exit 0 # success