mirror of
https://github.com/fleschutz/PowerShell.git
synced 2024-11-22 16:03:22 +01:00
Update check-drives.ps1
This commit is contained in:
parent
a8287d29cc
commit
c227fd586b
@ -7,15 +7,15 @@
|
|||||||
Specifies the minimum warning level (10 GB by default)
|
Specifies the minimum warning level (10 GB by default)
|
||||||
.EXAMPLE
|
.EXAMPLE
|
||||||
PS> ./check-drives.ps1
|
PS> ./check-drives.ps1
|
||||||
✅ Drive C: at 49% of 1TB, 512GB free
|
✅ Drive C: uses 49% of 1TB, 512GB free
|
||||||
✅ Drive D: at 84% of 4TB, 641GB free
|
✅ Drive D: uses 84% of 4TB, 641GB free
|
||||||
.LINK
|
.LINK
|
||||||
https://github.com/fleschutz/PowerShell
|
https://github.com/fleschutz/PowerShell
|
||||||
.NOTES
|
.NOTES
|
||||||
Author: Markus Fleschutz | License: CC0
|
Author: Markus Fleschutz | License: CC0
|
||||||
#>
|
#>
|
||||||
|
|
||||||
param([int]$minLevel = 10) # 10 GB minimum
|
param([int64]$minLevel = 10) # 10 GB minimum
|
||||||
|
|
||||||
function Bytes2String { param([int64]$bytes)
|
function Bytes2String { param([int64]$bytes)
|
||||||
if ($bytes -lt 1000) { return "$bytes bytes" }
|
if ($bytes -lt 1000) { return "$bytes bytes" }
|
||||||
@ -34,6 +34,7 @@ function Bytes2String { param([int64]$bytes)
|
|||||||
try {
|
try {
|
||||||
Write-Progress "⏳ Querying drives..."
|
Write-Progress "⏳ Querying drives..."
|
||||||
$drives = Get-PSDrive -PSProvider FileSystem
|
$drives = Get-PSDrive -PSProvider FileSystem
|
||||||
|
$minLevel *= 1000 * 1000 * 1000
|
||||||
Write-Progress -completed "."
|
Write-Progress -completed "."
|
||||||
foreach($drive in $drives) {
|
foreach($drive in $drives) {
|
||||||
$details = (Get-PSDrive $drive.Name)
|
$details = (Get-PSDrive $drive.Name)
|
||||||
@ -50,7 +51,7 @@ try {
|
|||||||
Write-Host "⚠️ Drive $name with $(Bytes2String $total) is nearly full, $(Bytes2String $free) free"
|
Write-Host "⚠️ Drive $name with $(Bytes2String $total) is nearly full, $(Bytes2String $free) free"
|
||||||
} else {
|
} else {
|
||||||
[int]$percent = ($used * 100) / $total
|
[int]$percent = ($used * 100) / $total
|
||||||
Write-Host "✅ Drive $name at $percent% of $(Bytes2String $total), $(Bytes2String $free) free"
|
Write-Host "✅ Drive $name uses $percent% of $(Bytes2String $total), $(Bytes2String $free) free"
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
exit 0 # success
|
exit 0 # success
|
||||||
|
Loading…
Reference in New Issue
Block a user