mirror of
https://github.com/fleschutz/PowerShell.git
synced 2025-08-09 21:07:40 +02:00
Added check-drive-space.ps1
This commit is contained in:
29
Scripts/check-drive-space.ps1
Executable file
29
Scripts/check-drive-space.ps1
Executable file
@ -0,0 +1,29 @@
|
||||
#!/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 = "", $WarningLevel = 50) #limit 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
|
||||
}
|
Reference in New Issue
Block a user