Updated check-drives.ps1

This commit is contained in:
Markus Fleschutz 2024-09-18 15:21:15 +02:00
parent d1a6b3ff87
commit cee7a19571

View File

@ -7,7 +7,7 @@
Specifies the minimum warning level (10GB by default)
.EXAMPLE
PS> ./check-drives.ps1
📂C: uses 489GB (53%) of 930GB, 📂D: uses 3TB (87%) of 4TB, 📂E: is empty
Drive C: uses 489GB (53%) of 930GB, D: uses 3TB (87%) of 4TB, E: is empty
.LINK
https://github.com/fleschutz/PowerShell
.NOTES
@ -30,25 +30,25 @@ try {
$drives = Get-PSDrive -PSProvider FileSystem
Write-Progress -completed "Done."
$status = ""
$reply = ""
$reply = "Drive "
foreach($drive in $drives) {
$details = (Get-PSDrive $drive.Name)
if ($IsLinux) { $name = $drive.Name } else { $name = $drive.Name + ":" }
[int64]$free = $details.Free
[int64]$used = $details.Used
[int64]$total = ($used + $free)
if ($reply -ne "") { $reply += ", " }
if ($reply -ne "Drive ") { $reply += ", " }
if ($total -eq 0) {
$reply += "📂$name is empty"
$reply += "$name is empty"
} elseif ($free -eq 0) {
$status = "⚠️"
$reply += "📂$name with ($(Bytes2String $total)) is FULL"
$reply += "$name with ($(Bytes2String $total)) is FULL"
} elseif ($free -lt $minLevel) {
$status = "⚠️"
$reply += "📂$name is nearly full ($(Bytes2String $free) of $(Bytes2String $total) left)"
$reply += "$name is nearly full ($(Bytes2String $free) of $(Bytes2String $total) left)"
} else {
[int64]$percent = ($used * 100) / $total
$reply += "📂$name uses $(Bytes2String $used) ($percent%) of $(Bytes2String $total)"
$reply += "$name uses $(Bytes2String $used) ($percent%) of $(Bytes2String $total)"
}
}
Write-Host "$status $reply"