mirror of
https://github.com/fleschutz/PowerShell.git
synced 2024-11-24 00:43:35 +01:00
30 lines
924 B
PowerShell
Executable File
30 lines
924 B
PowerShell
Executable File
#!/bin/powershell
|
|
<#
|
|
.SYNTAX ./check-drive-space.ps1 [<drive>] [<warning-level>]
|
|
.DESCRIPTION checks the given drive for free space left
|
|
.LINK https://github.com/fleschutz/PowerShell
|
|
.NOTES Author: Markus Fleschutz / License: CC0
|
|
#>
|
|
|
|
param($Drive = "", [int]$WarningLevel = 50) # warning level in GB
|
|
|
|
if ($Drive -eq "" ) {
|
|
$Drive = read-host "Enter drive to check"
|
|
}
|
|
|
|
try {
|
|
$FreeSpace = (get-psdrive $Drive).free
|
|
[int]$FreeSpace = (($FreeSpace / 1024) / 1024) / 1024
|
|
|
|
if ($FreeSpace -lt $WarningLevel) {
|
|
write-warning "Drive $Drive has only $FreeSpace GB free space left! (warning level is < $WarningLevel GB)"
|
|
exit 1
|
|
} else {
|
|
write-host -foregroundColor green "OK - drive $Drive has $FreeSpace GB free space left (warning level is < $WarningLevel GB)"
|
|
exit 0
|
|
}
|
|
} catch {
|
|
write-error "ERROR: line $($_.InvocationInfo.ScriptLineNumber): $($Error[0])"
|
|
exit 1
|
|
}
|