Updated the manuals

This commit is contained in:
Markus Fleschutz
2024-11-08 12:35:11 +01:00
parent 53eb60baa3
commit 54635c32da
636 changed files with 5289 additions and 2027 deletions

View File

@@ -6,14 +6,14 @@ This PowerShell script queries the free space of all drives and prints it.
Parameters
----------
```powershell
PS> ./check-drives.ps1 [[-minLevel] <Int64>] [<CommonParameters>]
/home/markus/Repos/PowerShell/scripts/check-drives.ps1 [[-minLevel] <Int64>] [<CommonParameters>]
-minLevel <Int64>
Specifies the minimum warning level (10GB by default)
Specifies the minimum warning level (5GB by default)
Required? false
Position? 1
Default value 10
Default value 5368709120
Accept pipeline input? false
Accept wildcard characters? false
@@ -26,8 +26,7 @@ Example
-------
```powershell
PS> ./check-drives.ps1
Drive C: uses 49% of 1TB - 512GB free
Drive D: uses 84% of 4TB - 641GB free
Drive C: uses 489GB (53%) of 930GB, D: uses 3TB (87%) of 4TB, E: is empty
```
@@ -48,51 +47,54 @@ Script Content
.DESCRIPTION
This PowerShell script queries the free space of all drives and prints it.
.PARAMETER minLevel
Specifies the minimum warning level (10GB by default)
Specifies the minimum warning level (5GB by default)
.EXAMPLE
PS> ./check-drives.ps1
✅ Drive C: uses 49% of 1TB - 512GB free
✅ Drive D: uses 84% of 4TB - 641GB free
✅ Drive C: uses 489GB (53%) of 930GB, D: uses 3TB (87%) of 4TB, E: is empty
.LINK
https://github.com/fleschutz/PowerShell
.NOTES
Author: Markus Fleschutz | License: CC0
#>
param([int64]$minLevel = 10) # 10 GB minimum
param([int64]$minLevel = 5GB)
function Bytes2String { param([int64]$number)
if ($number -lt 1KB) { return "$number bytes" }
if ($number -lt 1MB) { return '{0:N0}KB' -f ($number / 1KB) }
if ($number -lt 1GB) { return '{0:N0}MB' -f ($number / 1MB) }
if ($number -lt 1TB) { return '{0:N0}GB' -f ($number / 1GB) }
if ($number -lt 1PB) { return '{0:N0}TB' -f ($number / 1TB) }
return '{0:N0}GB' -f ($number / 1PB)
function Bytes2String { param([int64]$bytes)
if ($bytes -lt 1KB) { return "$bytes bytes" }
if ($bytes -lt 1MB) { return '{0:N0}KB' -f ($bytes / 1KB) }
if ($bytes -lt 1GB) { return '{0:N0}MB' -f ($bytes / 1MB) }
if ($bytes -lt 1TB) { return '{0:N0}GB' -f ($bytes / 1GB) }
if ($bytes -lt 1PB) { return '{0:N0}TB' -f ($bytes / 1TB) }
return '{0:N0}GB' -f ($bytes / 1PB)
}
try {
Write-Progress "Querying drives..."
$drives = Get-PSDrive -PSProvider FileSystem
$minLevel *= 1GB
Write-Progress -completed " "
Write-Progress -completed "Done."
$status = ""
$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 "Drive ") { $reply += ", " }
if ($total -eq 0) {
Write-Host "✅ Drive $name is empty"
$reply += "$name is empty"
} elseif ($free -eq 0) {
Write-Host "⚠️ Drive $name with $(Bytes2String $total) is full"
$status = "⚠️"
$reply += "$name with ($(Bytes2String $total)) is FULL"
} elseif ($free -lt $minLevel) {
Write-Host "⚠️ Drive $name with $(Bytes2String $total) is nearly full, $(Bytes2String $free) free"
$status = "⚠️"
$reply += "$name nearly full ($(Bytes2String $free) of $(Bytes2String $total) left)"
} else {
[int64]$percent = ($used * 100) / $total
Write-Host "✅ Drive $name uses $percent% of $(Bytes2String $total) - $(Bytes2String $free) free"
$reply += "$name uses $(Bytes2String $used) ($percent%) of $(Bytes2String $total)"
}
}
Write-Host "$status $reply"
exit 0 # success
} catch {
"⚠️ Error in line $($_.InvocationInfo.ScriptLineNumber): $($Error[0])"
@@ -100,4 +102,4 @@ try {
}
```
*(generated by convert-ps2md.ps1 using the comment-based help of check-drives.ps1 as of 08/15/2024 09:50:45)*
*(generated by convert-ps2md.ps1 using the comment-based help of check-drives.ps1 as of 11/08/2024 12:34:46)*