2021-12-03 10:12:56 +01:00
|
|
|
|
<#
|
|
|
|
|
.SYNOPSIS
|
2022-06-09 16:30:28 +02:00
|
|
|
|
Checks the free space of all drives
|
2021-12-03 10:12:56 +01:00
|
|
|
|
.DESCRIPTION
|
2022-10-16 11:06:11 +02:00
|
|
|
|
This PowerShell script checks all drives for free space left (10 GB by default).
|
2022-10-09 19:40:51 +02:00
|
|
|
|
.PARAMETER MinLevel
|
|
|
|
|
Specifies the minimum warning level (10 GB by default)
|
2021-12-03 10:12:56 +01:00
|
|
|
|
.EXAMPLE
|
|
|
|
|
PS> ./check-drives
|
|
|
|
|
.LINK
|
|
|
|
|
https://github.com/fleschutz/PowerShell
|
|
|
|
|
.NOTES
|
2022-06-09 16:30:28 +02:00
|
|
|
|
Author: Markus Fleschutz | License: CC0
|
2021-12-03 10:12:56 +01:00
|
|
|
|
#>
|
|
|
|
|
|
2022-10-09 19:40:51 +02:00
|
|
|
|
param([int]$MinLevel = 10) # 10 GB minimum
|
2022-10-09 12:34:06 +02:00
|
|
|
|
|
2021-12-03 10:12:56 +01:00
|
|
|
|
try {
|
|
|
|
|
$Drives = Get-PSDrive -PSProvider FileSystem
|
|
|
|
|
foreach($Drive in $Drives) {
|
2022-10-16 11:06:11 +02:00
|
|
|
|
$ID = $Drive.Name
|
|
|
|
|
$Details = (Get-PSDrive $ID)
|
|
|
|
|
[int]$Free = $Details.Free / 1GB
|
|
|
|
|
[int]$Used = $Details.Used / 1GB
|
2021-12-03 10:12:56 +01:00
|
|
|
|
[int]$Total = ($Used + $Free)
|
|
|
|
|
|
2021-12-06 19:21:15 +01:00
|
|
|
|
if ($Total -eq "0") {
|
2022-10-16 11:06:11 +02:00
|
|
|
|
"✅ Drive $ID is empty."
|
2021-12-06 19:21:15 +01:00
|
|
|
|
} elseif ($Free -lt $MinLevel) {
|
2022-10-16 11:06:11 +02:00
|
|
|
|
"⚠️ Drive $ID has only $Free GB of $Total GB left to use!"
|
2021-12-03 10:12:56 +01:00
|
|
|
|
} else {
|
2022-10-16 11:06:11 +02:00
|
|
|
|
"✅ Drive $ID has $Free GB of $Total GB left."
|
2021-12-03 10:12:56 +01:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
exit 0 # success
|
|
|
|
|
} catch {
|
2022-04-13 12:06:32 +02:00
|
|
|
|
"⚠️ Error in line $($_.InvocationInfo.ScriptLineNumber): $($Error[0])"
|
2021-12-03 10:12:56 +01:00
|
|
|
|
exit 1
|
2022-10-09 19:40:51 +02:00
|
|
|
|
}
|