Last active
April 4, 2017 05:56
-
-
Save chrisbrownie/102e252b027b1370a8ecd66f06aab481 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# 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