What is this?

This knowledgebase contains questions and answers about PRTG Network Monitor and network monitoring in general.

Learn more

PRTG Network Monitor

Intuitive to Use. Easy to manage.
More than 500,000 users rely on Paessler PRTG every day. Find out how you can reduce cost, increase QoS and ease planning, as well.

Free Download

Top Tags


View all Tags

Powershell with set-psdebug -strict

Votes:

0

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.

custom lastexitcode powershell strict

Created on Feb 12, 2013 2:02:55 PM

Last change on Feb 12, 2013 2:23:12 PM by  Konstantin Wolff [Paessler Support]



2 Replies

Votes:

0

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

Created on Feb 12, 2013 2:25:38 PM by  Konstantin Wolff [Paessler Support]

Last change on Feb 13, 2013 7:25:01 AM by  Konstantin Wolff [Paessler Support]



Votes:

0

Thanks for confirmation.

Frank

Created on Feb 12, 2013 9:10:30 PM




Disclaimer: The information in the Paessler Knowledge Base comes without warranty of any kind. Use at your own risk. Before applying any instructions please exercise proper system administrator housekeeping. You must make sure that a proper backup of all your data is available.