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

Custom EXE/script sensor returning 0



Running the following script on the probe device itself returns the correct value as it should, but running it via the senor it returns the value 0. Seems to be an issue with the Foreach loop? How can I get the right output returned to the map?

$checkservice=((Get-EC2Instance -Region us-east-1) | Select -ExpandProperty RunningInstance | where {$_.Tag.Key -eq "K12-Function" -and $_.Tag.Value -eq "jsched-asg"} | select -ExpandProperty PrivateIpAddress) $cnt=@(Foreach ($InstanceID in $checkservice) { invoke-command {get-service bbk12* -computername $args[0] | where {$_.Status -eq 'Running'}} -ArgumentList $InstanceID }).count write-host $cnt":ok"

Steven Belanger

custom-script-exe powershell return-code

Created on May 8, 2018 2:54:14 PM

2 Replies



Dear Steven,

I assume that the foreach loop is correct, but that the statement

$checkservice=((Get-EC2Instance -Region us-east-1) | Select -ExpandProperty RunningInstance | where {$_.Tag.Key -eq "K12-Function" -and $_.Tag.Value -eq "jsched-asg"} | select -ExpandProperty PrivateIpAddress)

yields an error message, or a different result when you run it with the 32 bit powershell. Please test that. If the 32 bit powershell shows the correct output, please check the sensor settings if you use the context of the probe, or the Windows credentials of the device object.

Created on May 8, 2018 9:05:36 PM by  Arne Seifert [Paessler Support]



Arne Seifert,

Changing the sensors Security Context setting to "Use Windows credentials of parent device" allowed the sensor to return the correct value of the script. Thanks for your help!

Steven Belanger

Created on May 9, 2018 11:22:24 AM

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.