I have successfully added a Demo sensor using the Demo Batch file provide in the PRTG Windows installation.
C:\Program Files (x86)\PRTG Network Monitor\Custom Sensors\EXEXML\Demo Batchfile - Returns static values in four channels.bat
I'm now trying to program the exact equivalent in a Powershell Script, but so far it's not working.
I get the Sensor message "XML: The returned XML does not match the expected schema. (code: PE233)"
As far as I can tell the XML formatting is as it should be. I've also set Powershell script permissions to 'Unrestricted'.
As a simple Powershell test I've simplified the XML generated to something very basic, but still no luck.
Cannot find any log messages that may gives further debug information.
Windows Powershell file 'test.ps1' contents:
$result = "<?xml version=`"1.0`" encoding=`"UTF-8`" ?>`r`n"\\ $result += "<prtg>`r`n"\\ $result += "<result>`r`n"\\ $result += "<channel>Minimum</channel>`r`n"\\ $result += "<value>3</value>`r`n"\\ $result += "</result>`r`n"\\ $result += "<text>Test values. OS: %OS%</text>`r`n"\\ $result += "</prtg>`r`n"\\ write-host $result\\ exit 0 \\
Not sure why it's not working. What am I missing?
Would it be possible for you to please provide a working Powershell Script (.ps1) that performs the exact same function as the 'Demo Batchfile - Returns static values in four channels.bat'
Thanks, Rod
Article Comments
Thankyou for the Powershell equivalent of the Demo.bat. I copied & pasted the script into Demo.ps1. It worked first time!
I then made a slight change & it stopped working with same error "XML: The returned XML does not match the expected schema. (code: PE233)".
I then recreated the script from your original demo script, but it no longer works despite many attempts & deleting/adding sensors & many .ps1 files.
Is there an error log I could check? Something that allows inspection of the returned XML? Something to check that Powershell is being called with appropriate permissions & is responding?
Thanks, Rod
Nov, 2020 - Permalink
Hello Rod,
You can enable the option "Write EXE result to disk" in the settings tab of the sensor. Let the sensor run for a couple of scan so that the log files can be generated. The files will be stored on the Probe host that runs the sensor, and per default they are stored in: C:\ProgramData\Paessler\PRTG Network Monitor\Logs\sensors
The files will be named "Result of Sensor ID" (where ID is the ID of the sensor).
Nov, 2020 - Permalink
All fixed. Thankyou.
The sensor log showed Demo.ps1 'cannot be loaded because running scripts is disabled on this system. For more information, see about_Execution_Policies at https:/go.microsoft.com/fwlink/?LinkID=135170.'
I had previously used Powershell to change the ExecutionPolicy to Unrestricted, but not used the LocalMachine scope, so it wasn't remembered after the current process closed.
I then used Powershell with Run as administrator option & executed "> Set-ExecutionPolicy -ExecutionPolicy Unrestricted -Scope LocalMachine", but it still didn't work.
Finally, I opened the Local Group Policy Editor and navigate to Computer Configuration -> Administrative Templates -> Windows Components -> Windows PowerShell. Double-click a setting called “Turn on Script Execution” on the right pane. Select the Enabled option. Beneath it, you can click the drop-down list to set the execution policy to “Allow local scripts and remote signed scripts". Click OK to save your changes.
Now it works.
Nov, 2020 - Permalink
Hello Rod,
Thank you for your post.
Here is a Powershell version of the script:
Please note that this script can be used only as a example for how the output should be formatted, since it only displays static values.
Kind regards,
Sasa Ignjatovic, Tech Support Team
Nov, 2020 - Permalink