2021-12-03 10:12:56 +01:00
|
|
|
|
<#
|
|
|
|
|
.SYNOPSIS
|
2022-01-29 12:47:46 +01:00
|
|
|
|
Checks all drives for free space left
|
2021-12-03 10:12:56 +01:00
|
|
|
|
.DESCRIPTION
|
2022-01-29 12:47:46 +01:00
|
|
|
|
This PowerShell script checks all drives for free space left (20 GB by default).
|
2021-12-03 10:12:56 +01:00
|
|
|
|
.PARAMETER MinLevel
|
|
|
|
|
Specifies the minimum level in Gigabyte
|
|
|
|
|
.EXAMPLE
|
|
|
|
|
PS> ./check-drives
|
2021-12-03 10:20:51 +01:00
|
|
|
|
✔️ Drive C has 172GB left (233GB total)
|
2021-12-03 10:12:56 +01:00
|
|
|
|
.LINK
|
|
|
|
|
https://github.com/fleschutz/PowerShell
|
|
|
|
|
.NOTES
|
2022-01-29 12:47:46 +01:00
|
|
|
|
Author: Markus Fleschutz / License: CC0
|
2021-12-03 10:12:56 +01:00
|
|
|
|
#>
|
|
|
|
|
|
|
|
|
|
param([int]$MinLevel = 20) # minimum level in GB
|
|
|
|
|
|
|
|
|
|
try {
|
|
|
|
|
$Drives = Get-PSDrive -PSProvider FileSystem
|
|
|
|
|
foreach($Drive in $Drives) {
|
|
|
|
|
$DriveDetails = (Get-PSDrive $Drive.Name)
|
|
|
|
|
[int]$Free = (($DriveDetails.Free / 1024) / 1024) / 1024
|
|
|
|
|
[int]$Used = (($DriveDetails.Used / 1024) / 1024) / 1024
|
|
|
|
|
[int]$Total = ($Used + $Free)
|
|
|
|
|
|
2021-12-06 19:21:15 +01:00
|
|
|
|
if ($Total -eq "0") {
|
|
|
|
|
$Reply = "Drive $($Drive.Name) is empty."
|
|
|
|
|
} elseif ($Free -lt $MinLevel) {
|
|
|
|
|
$Reply = "Drive $($Drive.Name) has only $Free GB left to use! $Used of $Total GB is in use."
|
2021-12-03 10:12:56 +01:00
|
|
|
|
} else {
|
2021-12-06 19:21:15 +01:00
|
|
|
|
$Reply = "Drive $($Drive.Name) has $($Free) GB left, $($Total) GB total."
|
2021-12-03 10:12:56 +01:00
|
|
|
|
}
|
2021-12-06 17:00:49 +01:00
|
|
|
|
& "$PSScriptRoot/give-reply.ps1" "$Reply"
|
2021-12-03 10:12:56 +01:00
|
|
|
|
}
|
|
|
|
|
exit 0 # success
|
|
|
|
|
} catch {
|
|
|
|
|
"⚠️ Error: $($Error[0]) ($($MyInvocation.MyCommand.Name):$($_.InvocationInfo.ScriptLineNumber))"
|
|
|
|
|
exit 1
|
|
|
|
|
}
|