Within PRTG, Scripts for custom sensors should normally only query properties/things (Usually Get- Powershell cmdlets) and those operations are usually quick.
You should perform any operations (Normally Set-, Start-, New-, etc cmdlets) outside the Custom Sensor's script.
In case you're just performing query operations and your script still takes a long time to complete (it can happen) there's a way around it:
Instead of running the long script within PRTG, run it from a Windows Scheduled Task, invoke the script in the following way(In most cases NO CHANGE is required to the original script):
powershell.exe C:\mylocation\myscript.ps1 > C:\mylocation\scriptoutput.txt |
And then for PRTG, create a new powershell script that you will add using the same custom sensor type as previously with the following code:
Get-Content -LiteralPath "C:\mylocation\scriptoutput.txt" |
The actual result is that the lengthy original script will be run as a task and it's original output will be written to a file, the second small script will only read/print the result of the original script.
That way, the execution time within PRTG will be massively improved, the sensor will no longer timeout and the load on the PRTG Probe will also decrease (As it will not keep open probe threads during the sensor's lengthy execution).
It's recommend to use an interval that is similar to the Windows Task's schedule, otherwise you'll repeatedly see the same value within PRTG if the file is queried multiple times before it is updated by the Scheduled Task. If you modify the sample script you can create a "Last Updated" message or channel to guarantee that the result is up-to-date.
Alternatively is is possible to create a File Sensor to warn you in case the output file wasn't updated for some reason, or a Windows Scheduled Task sensor to confirm that the task is indeed running as expected.
Update: If you're willing to modify the script, there's also another way this can be achieved. The script can be modified to actually send the data to PRTG directly instead of writing a file. This can be accomplished by sending the data to an HTTP Push Data Advanced Sensor. The result needs of the actual query should be stored in a variable which can then be sent to the corresponding PRTG Probe/Sensor (with the corresponding key) and the data will show up in the sensor in PRTG.
Add comment