Just discovered a funny problem with Powershell as Custiom EXE/XML sensor and PRTG Version 13.1.1.1086

I added a "set-psdebug –strict“ at the beginning of the script and the sensor was not working anymore, due an error.

…
<text>Exchange Lost:</text>
</prtg>
The variable '$LASTEXITCODE' cannot be retrieved because it has not been set.
At line:1 char:102
+ &'C:\Program Files (x86)\PRTG Network Monitor\custom sensors\EXEXML\exchangehealth.ps1' ; exit $LASTEXITCODE <<<< 
    + CategoryInfo          : InvalidOperation: (LASTEXITCODE:Token) [], RuntimeException
    + FullyQualifiedErrorId : VariableIsUndefined

The funny thing: I'm not using the variable '$LASTEXITCODE' anywhere in the code. And the "line 1" is a comment, so i assume that PRTG has some kind of wrapper around my script. No problem at all, i can simply remove that but you should be aware of that.


Article Comments

Hi,
you are correct. :)
We are wrapping up the scripts to get the exit code properly. As you enabled debugging this might conflict with the set -Noninteractive used in the wrapper.
The complete call would then look like this:

'Powershell.exe -Noninteractive -Command "&'''+exepath +'''" ' + params+ '; exit $LASTEXITCODE';

Best regards


Feb, 2013 - Permalink

Thanks for confirmation.

Frank


Feb, 2013 - Permalink