Hello all, being active to make up for some lost time last month.
The noise, the annoyance, what is happening now…
Disk drives tend to fill up fast, windows updates are taking more and more disk space and servers not getting rebooted won’t cleanup the winsxs folder.
I’ve written a simple function to monitor disk drives, run it with parameters to monitor multiple disks and monitor with your monitoring software, me, I prefer nagios.
I use exit codes for nagios which will give me the results for “OK”, “Warning” and “Critical”, which is the threshold you can define in this function
Function Monitor-Drives { param( [parameter(Mandatory=$true)]$Drives=("C"), $Warning="80", $Critical="90" ) # If the Warning or Critical is not defined with %, we set the % ourselves if($Warning -notmatch "%") { $Warning = "$Warning%" } if($Critical -notmatch "%") { $Critical = "$Critical%" } # Run through defined drives Foreach ($Drive in $Drives) { $Volume = Get-Volume -DriveLetter $Drive # | select DriveLetter,@{N='Size GB';E={[Math]::Round($_.Size/1GB)}},@{N='Freespace GB';E={[Math]::Round($_.SizeRemaining/1GB)}},@{N='Freespace %';E={($_.SizeRemaining/$_.Size).ToString("P")}} $PercFree = ($Volume.SizeRemaining/$Volume.Size).ToString("P") # Set the status to OK if($PercFree -lt $Warning) { Write-Host "OK - Drive $Drive`:" $PercFree "free" exit 0; } elseif ($PercFree -gt $Warning -and $PercFree -lt $Critical) { # Set the status to Warning Write-Host "Warning - Drive $Drive`:" $PercFree "free" exit 1; # Set the status to Critical } elseif ($PercFree -gt $Critical) { Write-Host "CRITICAL - Drive $Drive`:" $PercFree "free" exit 2; # If all fails, give the UNKNOWN status } else { exit 3; } } }
Then run the script with parameters
Monitor-Drives -Drives C,E -Warning 80 -Critical 90
My results…
OK - Drive C: 34,25% free OK - Drive E: 38,31% free
Guess I’m ok for now…
Hallgrimur #TheMachine