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

EXE/Script Sensor Channel shows No Data




I have created a NON XML custom EXE/Script sensor that uses a PowerShell script to count the number of files without a .old extension older than 2 hours in a folder on a remote machine. The only parameter I'm specifying is %host:


$UnprocessedFiles = Invoke-Command -ComputerName $args[0] -ScriptBlock {Get-ChildItem -File -Path 'D:\SMS Folders\Inbound CAD'}

$UnprocessedFilesError = $UnprocessedFiles | Where-Object {$_.Name -notmatch ".old" -and $_.LastWriteTime -lt $(Get-Date).AddHours(-2)}


$Count = ($UnprocessedFilesError | Measure-Object).Count

Write-Host "$Count`: $Count Unprocessed File(s) found in D:\SMS Folders\Inbound CAD. SMS is not processing inbound CAD files."
exit 2


Write-Host "0:No unprocessed CAD files found"
exit 0

The script works when run from the probe server by my user account as long as I specify the computer name in the invoke-command.

When I set it up as a sensor I have the channel for my Count set as an integer. The value it returns is the count of files older than 2 hours.

I have ensured the execution policy is set to bypass.

When I set the sensor to run in the security context of the probe service account (local system) it can't run the invoke-command because its running as local system so it shows the OK result on the sensor. However, I can see the count channel show up with a value of 0 and I can see the execution time channel with the time it took to run the script.

When I run the sensor in the security context of the parent device (prtg service account with local admin to the target machine) the script runs successfully and I can see it change the sensor status to error and set the expected last message... But the Count channel doesn't show up on the sensor and the two channels I can see Downtime and Execution Time show "No Data".

If I break the sensor by setting it to run as the probe service account for one run the Count channel does show up but as soon as I set it back to run under the service account all my channels including the count show up as "No Data".

I've tried recreating the sensor.

I tried running the script under the PRTG Service account (local system) and using the %windowsuser and %windowspassword place holders to pass the credentials to a PSCredential and used it in the invoke-command with the same result.

I'm not sure what else to try or what the problem could be. If I can't get it working I'll try the XML Advanced sensor but I'd prefer not to if I can get this working.

Thanks for any help you can provide.

channel customsensor nodata powershell windows

Created on Mar 25, 2017 5:58:23 PM

Last change on Mar 27, 2017 9:08:52 AM by  Luciano Lingnau [Paessler]

1 Reply

Accepted Answer



Hello there,
thank you for your KB-Post.

The EXE/Script Sensor and EXE/Script Advanced Sensor will behave exactly the same in this regard, there's no practical difference regarding authentication.

Impersonation is very tricky and can give you a headache. You might want to use the %windowsuser, %windowsdomain and %windowspassword and provide them to the script via parameters. There, use them to build a credential use these when running the Invoke-Command:

$ps_cred = New-Object System.Management.Automation.PSCredential -ArgumentList "domain\account",(ConvertTo-SecureString -AsPlainText -Force -String: "mypassword")
Invoke-Command -ComputerName server.domain.tld -Credential $ps_cred -Authentication Credssp -ScriptBlock 

There's a similar case and example here:

You've mentioned that while troubleshooting there are cases where the script fails (no value) but comes up green. This is because you're not doing any try/catch statements, so PRTG doesn't "know" that the query actually failed and prints $Count which is null. There's an example of try/catch with powershell in these scripts/posts:

Essentially, it works like this:

try {
$a = Invoke-WebRequest -Uri $url -UseBasicParsing # Script tries to do something
}catch{ # Should it fail to do the above, the following will happen
    Write-Output "<prtg>"
    Write-Output "<error>1</error>"
    Write-Output "<text>Query Failed: $($_.Exception.Message)</text>"
    Write-Output "</prtg>"

It will work with non-advanced sensors too, but you need to control it via exit codes:

2System Error (e.g. a network/socket error)
3Protocol Error (e.g. web server returns a 404)
4Content Error (e.g. a web page does not contain a required word)

And on a third note, configuring the Probe Service to run with a domain service account (with appropriate permissions), something like "svc_account_prtg" created for this purpose is also a good approach, this way the Probe Service will have valid credentials when running custom-script sensors. The sensor setting should be turned to Use security context of probe service in this case.

On a last node. A great "companion" for low-level testing and troubleshooting the execution of custom-script sensors in PRTG is Process Monitor from Sysinternals. It allows you to see which account and parameters are being used to run the process and if there are any errors during the execution.

Best Regards,
Luciano Lingnau [Paessler Support]

Created on Mar 27, 2017 9:25:11 AM by  Luciano Lingnau [Paessler]

Last change on Mar 27, 2017 9:26:52 AM by  Luciano Lingnau [Paessler]

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.