
Scott Prince (Customer) asked a question.
Hello, my organization is looking to setup an active monitor that monitors available disk capacity, basically we'd like to monitor all logical disks and have a monitor alert if and when the disk drops below 10% of available capacity.
I have setup a basic PS script to check all disks and failures within the $context.SetResult however the result, when testing in WUG always returns as 0 (no disks are below capacity), if I was to comment out the $context.SetResult and run the script on a known server where a disk has less than 10% capacity then the script returns the correct outputs into $result = 1 & $ResultText = "Disks with less than 10% free space: $($failedDisks -join ', ')"
Would anyone be able to advise me exactly where I'm going wrong when I copy the script into WUG.
- $disks = Get-WmiObject Win32_LogicalDisk | Where-Object { $_.DriveType -eq 3 } # Retrieves logical disks excluding CD-ROM, network drives, etc.
- $result = 0
- $failedDisks = @()
-
- ForEach ($disk in $disks) {
- $freeSpacePercent = [math]::Round(($disk.FreeSpace / $disk.Size) * 100, 2)
-
- if ($freeSpacePercent -lt 10) {
- $result = 1
- $failedDisks += $disk.DeviceID
- }
- if ($result -eq 1) {
- $resultText = "Disks with less than 10% free space: $($failedDisks -join ', ')"
- }
- else {
- $resultText = "All disks have more than 10% free space"
- }
- }
- # Always set the active monitor result: 0 = success, 1 = failure
- $Context.SetResult($result, $resultText);