This article applies to PRTG Network Monitor 8.1.2 or later
Using Parameters with EXE/Script Sensors
In order to correctly pass one or more parameters to a script, or when using %placeholders, please enclose every single Parameter in quotes:
- For PowerShell scripts, please use single quotation marks ' '
- For all other scripts, please use double quotes " "
If you do not use quotes, every space will be regarded a separator, thus dividing one parameter into two.
In order to test how parameters are passed to a script, you can set up an EXE/Script Sensor using one of the following simple scripts.
Return EXE Parameters Using Powershell
Save the following script as "Demo Powershell Script - Check EXE Sensor Parameters.ps1" to the Custom EXE\EXE sub folder of your PRTG program directory.
foreach ($arg in $args)
{
$s += """" + $arg + """ "
}
$x = [string]$args.Length + ":" + $s
write-Host $x
Once setup as an EXE/Script Sensor, you will see the parameters you have entered in the Settings tab of this sensor returned in the sensor's Last Message field. In this output, every single value will be enclosed in quotes.
See Also
Powershell 32bit or 64Bit and Execution Policy
Return EXE Parameters Using VBScript
Save the following script as "Demo VBScript - Check EXE Sensor Parameters.vbs" to the Custom EXE\EXE sub folder of your PRTG program directory.
Dim i,c, str
c = WScript.Arguments.Count
if c = 0 then
WScript.echo c&":No Arguments"
else
for i = 0 to c - 1
str = str + """" + WScript.Arguments(i) +""" "
next
WScript.echo c & ":" & str
end if
Once setup as an EXE/Script Sensor, you will see the parameters you have entered in the Settings tab of this sensor returned in the sensor's Last Message field. In this output, every single value will be enclosed in quotes.
More
A detailed description of EXE/Script sensors can be found in the Detailed HTTP API Documentation.
Add comment