This article applies as of PRTG 22
How do I enter multiple parameters for an EXE/Script sensor in PRTG and ensure they are correctly forwarded to my script?
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.
EXAMPLE for POWERSHELL:
Parameter field:'%device' '%name' '%status' '%down' '%message'
First line in powershell to receive those parameters:param([string]$IPServer = "N/A",[string]$IPService = "N/A",[string]$IPStatus = "N/A", [string]$IPDown = "N/A",[string]$IPMessage = "N/A")
After that all of the powershell variables will be filled in from Network Monitor. If there is a failure for some reason, then you will get N/A as your value.
When you encounter the sensor message contains a single quote it breaks up the '%message' parameter in the script.
The parameters for the script: '%sensor' '%sensorid' '%status' '%message' '%device' '%since' '%lastup' '' '' '' '%prio'
'Escape a single quote '' using a double single quote'
See the help for the quoting rules. Check out the help in the powershell command line by typing:
Get-Help about_Quoting_Rules
It explains that backticks are interpreted literally in single-quoted strings:
-- Because the contents of single-quoted strings are interpreted literally, you cannot use the
-- backtick character to force a literal character interpretation in a single-quoted string.
More
- Find a detailed description of EXE/Script sensors in the PRTG Manual: Custom Sensors.
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.