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

Problems with Powershell return value



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()
	#... 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


$output = ("{0} :{1}") -f $retvalue,$retmsg
Write-Host $output
exit $retvalue

custom-script-exe custom-sensor powershell script

Created on Oct 28, 2011 11:57:05 AM

Last change on Mar 19, 2015 3:51:00 PM by  Martina Wittmann [Paessler Support]

2 Replies

Accepted Answer



By design, PRTG does not accept values from sensors in a Down status. This is because a down status is considered a major outage and no values are expected in such a case.

If you still want to receive values in your custom sensor, please do not use the return value 2.

Created on Oct 28, 2011 12:46:44 PM by  Daniel Zobel [Product Manager]



Or as an alternative, if you need that values, try to modify you scrip so it can be used as an exexml sensortype:

So add this to your Script, before the exit command:

$CHANNELNAME= "name your channel"


and replace "exit $retvalue" by "exit 0"

Finally, after you have the sensor working in prtg, let prtg make the decision how to deal with the channel value (config in sensors channeltab).

Created on Nov 9, 2011 7:56:26 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.