This article applies as of PRTG 22
Using parameters with EXE/Script sensors
To correctly pass one or more parameters to a script, or when using placeholders, put every single parameter in quotes:
- For PowerShell scripts, use single quotation marks ' '
- For all other scripts, use double quotes " "
If you do not use quotes, every space is regarded as a separator, thus dividing one parameter into two.
To test how parameters are passed to a script, you can set up an EXE/Script sensor and use one of the following simple scripts.
Note: We recommend that you not edit the demo files in the \Custom Sensors\EXE subfolder of the PRTG program directory. Create your own new files and make sure to give them unique names that do not start with Demo, for example.
Return EXE parameters using PowerShell
Save the following script as Check EXE Sensor Parameters.ps1 to the Custom Sensors\EXE subfolder of the PRTG program directory.
foreach ($arg in $args)
{
$s += """" + $arg + """ "
}
$x = [string]$args.Length + ":" + $s
write-Host $x
After you have set up the EXE/Script sensor, you will see that the parameters you have entered in the Settings tab of this sensor are returned in the sensor's Last Message field. In this output, every single value is put in quotes.
See also
PowerShell 32-bit or 64-Bit and Execution Policy
Return EXE parameters using VBScript
Save the following script as Check EXE Sensor Parameters.vbs to the Custom Sensors\EXE subfolder of the 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
After you have set up the EXE/Script sensor, you see that the parameters you have entered in the Settings tab of this sensor are returned in the sensor's Last Message field. In this output, every single value is put in quotes.
More
Add comment