Skip to content

Instantly share code, notes, and snippets.

@chrisbrownie
Last active April 4, 2017 05:56
Show Gist options
  • Save chrisbrownie/102e252b027b1370a8ecd66f06aab481 to your computer and use it in GitHub Desktop.
Save chrisbrownie/102e252b027b1370a8ecd66f06aab481 to your computer and use it in GitHub Desktop.
# Alert whenever the free space on disk falls below the following factor
# .20 = 20 %
# .10 = 10 %
$alarmThreshold = ".20"
$pushoverUrl = "https://api.pushover.net/1/messages.json"
$pushoverToken = ""
$pushoverUserKey = ""
foreach ($disk in (Get-WmiObject -Class Win32_LogicalDisk | Where {$_.DriveType -eq 3})) {
# Calculate the percent free
$percentFree = $disk.FreeSpace/$disk.Size
if ($percentFree -lt $alarmThreshold) {
# The disk has less free space than the threshold, trigger the alarm
[int]$freeSpaceGb = $disk.FreeSpace/1GB
$params = @{
"token" = $pushoverToken
"user" = $pushoverUserKey
"title" = "$($env:COMPUTERNAME) $($disk.DeviceID) low free space!"
"message" = "$($env:COMPUTERNAME) <b>$($disk.DeviceID)</b> has only $freeSpaceGb GB free space. This is below the configured threshold."
}
Invoke-WebRequest -Uri $pushoverUrl -Method POST -Body $params
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment