What is this?

This knowledgebase contains questions and answers about PRTG Network Monitor and network monitoring in general. You are invited to get involved by asking and answering questions!

Learn more

PRTG Network Monitor

Intuitive to Use. Easy to manage.
300.000 administrators have chosen PRTG to monitor their network. Find out how you can reduce cost, increase QoS and ease planning, as well.

Free Download

Top Tags


View all Tags

Powershell custom sensor issue

Votes:

0

Your Vote:

Up

Down

I've written a couple of custom sensors using powershell (which works when run in powershell). However when these custom sensors are added to a device, an error appears:

Query Failed: Could not load file or assembly 'Microsoft.SqlServer.BatchParser, Version=15.100.0.0, Culture=neutral, PublicKeyToken=89845dcd8080cc91' or one of its dependencies. The system cannot find the file specified.

Nothing seems to make this implementation work.

However, when I wrap this PS1 file in a batch script and save as a separate custom sensor, it works: example batch script

cd %SystemRoot%\sysnative\WindowsPowerShell\v1.0\
powershell.exe -file "C:\Program Files (x86)\PRTG Network Monitor\Custom Sensors\EXEXML\test-Stats.ps1"

in other words, i'm forcing the PS1 script to be run using a different powershell architecure.

Is there a PRTG fix for this please?

custom-sensor prtg sensor

Created on Feb 3, 2021 10:35:46 PM by  Tolu (0) 1

Last change on Feb 4, 2021 6:54:07 AM by  Felix Wiesneth [Paessler Support]



5 Replies

Votes:

0

Your Vote:

Up

Down

Hello,

Thank you for your message.

Can you please provide us the following information:

  • PowerShell version
  • .NET Framework installed
  • Windows version

Please, share the content of the script as well (without any confidential information).

Regards.

Created on Feb 8, 2021 2:28:35 PM by  Florian Lesage [Paessler Support]

Last change on Feb 8, 2021 2:28:50 PM by  Florian Lesage [Paessler Support]



Votes:

0

Your Vote:

Up

Down

Hello,

PSVersion5.1.14393.3866
DotNet runtime5.0.1 (x86, x64)
DotNet core runtime3.1.8
OSversionWin server 2016 standard
$sqlsmd = " a sql select query that returns 6 fields of data"


try {
    

    $result = Invoke-Sqlcmd -Query $sqlsmd -ServerInstance $target -Database $DataBase
}
catch {
    Write-Output "echo    <?xml version=""1.0"" encoding=""Windows-1252"" ?>"
    Write-Output "echo    <prtg>"
    Write-Output "echo    <error>1</error>"
    Write-Output "echo    <text>Query Failed: $($_.Exception.Message)</text>"
    Write-Output "echo    </prtg>"
    Exit
}

Created on Feb 8, 2021 3:04:40 PM by  Tolu (0) 1

Last change on Feb 8, 2021 3:55:02 PM by  Felix Wiesneth [Paessler Support]



Votes:

0

Your Vote:

Up

Down

Hello,

Thank you for the information.

Can you please execute the PowerShell script by using PowerShellScriptRunner.exe located under "C:\Program Files (x86)\PRTG Network Monitor", with the command:

.\PowerShellScriptRunner.exe -script="full script path"

What result do you get ?

Regards.

Created on Feb 9, 2021 8:49:42 AM by  Florian Lesage [Paessler Support]

Last change on Feb 9, 2021 8:50:08 AM by  Florian Lesage [Paessler Support]



Votes:

0

Your Vote:

Up

Down

Hi Florian,

what's the purpose of using this as opposed to the current work around I have in place which is:

powershell.exe -file "C:\Program Files (x86)\PRTG Network Monitor\Custom Sensors\EXEXML\xxx-Stats.ps1"

I guess I was hoping for a fix or a way of running the sensor as as described in the knowledgebase.

regards

Created on Feb 12, 2021 10:19:20 AM by  Tolu (0) 1



Votes:

0

Your Vote:

Up

Down

Hello,

Can you continue to use your workaround without any issue. The instruction I provided above should help to check where this error comes from exactly when directly executing the script via PRTG (without the workaround).

Have you tried to execute the script by using the option Use Windows credentials of parent device next to Security Context in the sensor settings? If not, I invite you to test that option which will execute the script as the user defined in the parent device settings (under Credentials for Windows Systems) instead of Local System.

Regards.

Created on Feb 15, 2021 6:42:01 AM by  Florian Lesage [Paessler Support]



Please log in or register to enter your reply.


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.