Hi forum
i wrote a simple local check to keep track of all the disk quotas of all our 900 file servers since the Agent (at least 1.5, havent tried 1.6 yet) cannot handle it out of the box.
The check reads out all set quotas, translates them human readable (with thresholds set to 85/95%) and even makes pretty graphs too 
Requires the cmdlet Get-FsrmQuota which is automatically installed with File Server Resource Manager
$OK=0
$Warn=1
$Crit=2
$Unk=3
$Quotas=@(Get-FsrmQuota | Select-Object Path, Size, Usage)
$Output = ββ
$Output1 = ββ
echo <
<<local
>>
>
foreach ($Quota in $Quotas) {
$Size=($Quota.Size / 1gb)
$Usage=[math]::Round($Quota.Usage / 1gb,1)
$Path=($Quota.Path)
$Percent=($Usage / $Size * 100)
$warnvalue=85
$critvalue=95
if ($Percent -lt $warnvalue)
{$Output = $OK.ToString() + " Disk_Quota_" +$Path + " " + βUsage=β + $Percent + β;β + $warnvalue + β;β + $critvalue + " Size=" + $Size + " GB, Usage=" + $Usage + " GB " + $Percent + β%β}
elseif ($Percent -ge $warnvalue -and $Percent -lt $critvalue)
{$Output = $Warn.ToString() + " Disk_Quota_" +$Path + " " + βUsage=β + $Percent + β;β + $warnvalue + β;β + $critvalue + " Size=" + $Size + " GB, Usage=" + $Usage + " GB " + $Percent + β%β}
elseif ($Percent -ge $critvalue)
{$Output = $Crit.ToString() + " Disk_Quota_" +$Path + " " + βUsage=β + $Percent + β;β + $warnvalue + β;β + $critvalue + " Size=" + $Size + " GB, Usage=" + $Usage + " GB " + $Percent + β%β}
$Output1 = $Output1 + β|β + $Output
write-host $Output
}
You local check a little bit shorter and better readable 
# Quota Output as Local Check for CMK
$Quotas = @(Get-FsrmQuota | Select-Object Path, Size, Usage)
foreach ($Quota in $Quotas) {
$Size = ($Quota.Size / 1gb)
$Usage = [math]::Round($Quota.Usage / 1gb, 1)
$Path = ($Quota.Path)
$Percent = ($Usage / $Size * 100)
Write-Host("P Disk_Quota_" + $Path + " Usage=" + "{0:N0}" -f $Percent + ";85;95|Size=" + "{0:N0}" -f $Size + " The quota usage in percent and GB size")
}
The Status is dynamically calculated by CMK itself. You donβt need to invest to much time for if-then-else statements anymore.
1 Like
Hi Andreas
thank you so much. Indeed this is muss less code and is much better to read. I did some minor cosmetic changes for the output and this is the final result:
# Quota Output as Local Check for CMK
$Quotas = @(Get-FsrmQuota | Select-Object Path, Size, Usage)
foreach ($Quota in $Quotas) {
$Size = ($Quota.Size / 1gb)
$Usage = [math]::Round($Quota.Usage / 1gb, 1)
$Path = ($Quota.Path)
$Percent = ($Usage / $Size * 100)
Write-Host("P Disk_Quota_" + $Path + " Usage=" + "{0:N0}" -f $Percent + ";85;95|Size=" + "{0:N0}" -f $Size + " Used: $Percent%, $Usage GB")
}
No problem - my code was only written without the real possibility to test 
Thanks for this.
I recommend a few further tweaks to the Write-Host
line:
Write-Host ("P Disk_Quota_{0} Usage={1:N2};85;95|Size={2:N0} Used: {1:N2}%, {3} GB" -f $Path.Replace(' ', '_'), $Percent, $Size, $Usage)
The main thing is that I replace spaces with underscores in the path, to prevent them breaking the check output.
I also use :N2
to rein in the percentage decimal places a bit, and I also neaten it up a bit by removing concatenations and putting it all in a single format string.