Update check-drives.ps1

This commit is contained in:
Markus Fleschutz 2024-02-08 12:09:35 +01:00
parent 188653a71d
commit 15f69e32aa

View File

@ -4,7 +4,7 @@
.DESCRIPTION .DESCRIPTION
This PowerShell script queries the free space of all drives and prints it. This PowerShell script queries the free space of all drives and prints it.
.PARAMETER minLevel .PARAMETER minLevel
Specifies the minimum warning level (10 GB by default) Specifies the minimum warning level (10GB by default)
.EXAMPLE .EXAMPLE
PS> ./check-drives.ps1 PS> ./check-drives.ps1
Drive C: uses 49% of 1TB · 512GB free Drive C: uses 49% of 1TB · 512GB free
@ -17,24 +17,19 @@
param([int64]$minLevel = 10) # 10 GB minimum param([int64]$minLevel = 10) # 10 GB minimum
function Bytes2String { param([int64]$bytes) function Bytes2String { param([int64]$number)
if ($bytes -lt 1000) { return "$bytes bytes" } if ($number -lt 1KB) { return "$number bytes" }
$bytes /= 1000 if ($number -lt 1MB) { return '{0:N0}KB' -f ($number / 1KB) }
if ($bytes -lt 1000) { return "$($bytes)KB" } if ($number -lt 1GB) { return '{0:N0}MB' -f ($number / 1MB) }
$bytes /= 1000 if ($number -lt 1TB) { return '{0:N0}GB' -f ($number / 1GB) }
if ($bytes -lt 1000) { return "$($bytes)MB" } if ($number -lt 1PB) { return '{0:N0}TB' -f ($number / 1TB) }
$bytes /= 1000 return '{0:N0}GB' -f ($number / 1PB)
if ($bytes -lt 1000) { return "$($bytes)GB" }
$bytes /= 1000
if ($bytes -lt 1000) { return "$($bytes)TB" }
$bytes /= 1000
return "$($bytes)PB"
} }
try { try {
Write-Progress "Querying drives..." Write-Progress "Querying drives..."
$drives = Get-PSDrive -PSProvider FileSystem $drives = Get-PSDrive -PSProvider FileSystem
$minLevel *= 1000 * 1000 * 1000 $minLevel *= 1GB
Write-Progress -completed " " Write-Progress -completed " "
foreach($drive in $drives) { foreach($drive in $drives) {
$details = (Get-PSDrive $drive.Name) $details = (Get-PSDrive $drive.Name)