I have a very simple powershell script. In a function is some logic and the return value of the function should be the exit code for the script. For the result 0 and 1 (ok and warning) the script works well, but if the function returns 2 (Error) I get no result in PRTG. The returned message is shown as "2 :2 RL disabled!" and the last value is empty! What is the reason for this behaviour? I hope it is reproducable for you.
The script:
[int]$retvalue = 0 [string]$retmsg = "Dummy" function TestFunction() { [int]$myretvalue=0 $retmsg="" $countDisabled=2 #... here comes some logic ... if($countDisabled -eq 0) { $script:retmsg = "All enabled" $myretvalue = 0 } else { $script:retmsg = ("{0} RL disabled") -f $countDisabled $myretvalue = 2 # 0 or 1 works, 2 not! } return $myretvalue } $retvalue=TestFunction $output = ("{0} :{1}") -f $retvalue,$retmsg Write-Host $output exit $retvalue
Add comment