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?


Article Comments

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.


Feb, 2021 - Permalink

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
}


Feb, 2021 - Permalink

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.


Feb, 2021 - Permalink

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


Feb, 2021 - Permalink

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.


Feb, 2021 - Permalink