Hi,

I have a simple script with following code

$files=get-childitem "C:\Temp\test" | where {$_.extension -ne ".txt" -and $_.PSIsContainer -ne "True"}

$numberfiles=$files.count

 if ($numberfiles -gt "4")    
    {
    write-host "$numberfiles":"$numberfiles files found"
    exit 2
	}

elseif ($numberfiles -gt "0") 
	{
      write-host "$numberfiles":"$numberfiles files found"
      exit 1
	}

else {write-host "no files found"
	exit 0
	}

Basically:

  • no files in directory: exit code 0, green, OK.
  • more than 0 files but less or equal than 4 files in directory: exit code 1, yellow, warning.
  • more than 4 files in directory: exit code 2, red, critical.

This all works, but for some reason, PRTG does not keep the value when exit code 2 is used. Only when exit code 0 or 1 is used, it keeps the value.

Screenshot: https://imgur.com/a/RMTFGER

Any ideas why this might happen?


Article Comments

Hi there,

As the exit codes 2-4 are considered as errors you don't get the value. The best way in your case would be to not use any exit code (only 0) and to define a limit in the "Value"-channel that triggers a warning/error. There you can also define a warning/error message.

Best regards.


Jul, 2019 - Permalink

Hi Dariusz,

Works like a charm, thanks so much!


Jul, 2019 - Permalink