|
7 | 7 | Specifies the minimum warning level (10 GB by default)
|
8 | 8 | .EXAMPLE
|
9 | 9 | PS> ./check-drives
|
10 |
| - ✅ C drive uses 87GB of 249GB |
| 10 | + ✅ Drive C: uses 87GB of 249GB |
11 | 11 | .LINK
|
12 | 12 | https://github.com/fleschutz/PowerShell
|
13 | 13 | .NOTES
|
@@ -35,24 +35,23 @@ function Bytes2String { param([int64]$Bytes)
|
35 | 35 | try {
|
36 | 36 | Write-Progress "⏳ Querying drives..."
|
37 | 37 | $Drives = Get-PSDrive -PSProvider FileSystem
|
38 |
| - Write-Progress -completed "done." |
| 38 | + Write-Progress -completed "." |
39 | 39 | 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 + ":" } |
42 | 42 | [int64]$Free = $Details.Free
|
43 | 43 | [int64]$Used = $Details.Used
|
44 | 44 | [int64]$Total = ($Used + $Free)
|
45 | 45 |
|
46 | 46 | if ($Total -eq 0) {
|
47 |
| - Write-Host "✅ $ID drive is empty" |
| 47 | + Write-Host "✅ Drive $ID is empty" |
48 | 48 | } 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" |
50 | 50 | } 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)" |
54 | 52 | } 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" |
56 | 55 | }
|
57 | 56 | }
|
58 | 57 | exit 0 # success
|
|
0 commit comments