Skip to content

Commit 920c0d4

Browse files
committed
Update check-drives.ps1
1 parent 0d5646e commit 920c0d4

File tree

1 file changed

+9
-10
lines changed

1 file changed

+9
-10
lines changed

Scripts/check-drives.ps1

Lines changed: 9 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
Specifies the minimum warning level (10 GB by default)
88
.EXAMPLE
99
PS> ./check-drives
10-
C drive uses 87GB of 249GB
10+
Drive C: uses 87GB of 249GB
1111
.LINK
1212
https://github.com/fleschutz/PowerShell
1313
.NOTES
@@ -35,24 +35,23 @@ function Bytes2String { param([int64]$Bytes)
3535
try {
3636
Write-Progress "⏳ Querying drives..."
3737
$Drives = Get-PSDrive -PSProvider FileSystem
38-
Write-Progress -completed "done."
38+
Write-Progress -completed "."
3939
foreach($Drive in $Drives) {
40-
$ID = $Drive.Name
41-
$Details = (Get-PSDrive $ID)
40+
$Details = (Get-PSDrive $Drive.Name)
41+
if ($IsLinx) { $ID = $Drive.Name } else { $ID = $Drive.Name + ":" }
4242
[int64]$Free = $Details.Free
4343
[int64]$Used = $Details.Used
4444
[int64]$Total = ($Used + $Free)
4545

4646
if ($Total -eq 0) {
47-
Write-Host "$ID drive is empty"
47+
Write-Host "Drive $ID is empty"
4848
} elseif ($Free -eq 0) {
49-
Write-Host "⚠️ $ID drive with $(Bytes2String $Total) is full!"
49+
Write-Host "⚠️ Drive $ID with $(Bytes2String $Total) is 100% full"
5050
} elseif ($Free -lt $MinLevel) {
51-
Write-Host "⚠️ $ID drive with $(Bytes2String $Total) is nearly full ($(Bytes2String $Free) free)!"
52-
} elseif ($Used -lt $Free) {
53-
Write-Host "$ID drive uses $(Bytes2String $Used) of $(Bytes2String $Total)"
51+
Write-Host "⚠️ Drive $ID with $(Bytes2String $Total) is nearly full ($(Bytes2String $Free) free)"
5452
} else {
55-
Write-Host "$ID drive has $(Bytes2String $Free) of $(Bytes2String $Total) free"
53+
[int]$Percent = ($Used * 100) / $Total
54+
Write-Host "✅ Drive $ID $Percent% full, $(Bytes2String $Free) of $(Bytes2String $Total) free"
5655
}
5756
}
5857
exit 0 # success

0 commit comments

Comments
 (0)