What is this?

This knowledgebase contains questions and answers about PRTG Network Monitor and network monitoring in general.

Learn more

PRTG Network Monitor

Intuitive to Use. Easy to manage.
More than 500,000 users rely on Paessler PRTG every day. Find out how you can reduce cost, increase QoS and ease planning, as well.

Free Download

Top Tags


View all Tags

Using Invoke-Sqlcmd not working from custom sensor

Votes:

0

Trying to get a custom sensor working with Invoke-Sqlcmd in it. The PowerShell is short and works from the server that the probe is on, using the Windows account that the probe is using. However when run by PRTG, the message is that Import-Sqlcmd is not found.

$cred = New-object System.Management.Automation.PSCredential('xxxx_ro',(Get-Content 'C:\Program Files (x86)\PRTG Network Monitor\Custom Sensors\EXE\xxxx_ro.txt' | ConvertTo-SecureString))
#$cred = New-object System.Management.Automation.PSCredential('xxxx_ro',(ConvertTo-SecureString $args[0] -AsPlainText -Force))
$connection = "Password=$($cred.GetNetworkCredential().Password);Persist Security Info=True;User ID=$($cred.UserName);Initial Catalog=xxxx-db;Data Source=xxxx-svr.database.windows.net"
$sql = "SELECT TOP 1 DATEDIFF(SECOND, UTCDateTimeCreated, GETUTCDATE()) Recent FROM [Event].Record ORDER BY Id DESC"
$value = Invoke-Sqlcmd -Query $sql -ConnectionString $connection
$valueRecent = 1

I know that the simple example above can be achieved using a MsSql sensor instead but my real world examples involve the sensor pulling data from multiple different SQL and non-SQL sources and comparing them. This is why I'm using PowerShell.

invoke-sqlcmd powershell prtg

Created on Jul 22, 2022 10:54:17 AM



1 Reply

Votes:

0

Hello,

Thanks for contacting us.

What is the exact error message displayed when adding the sensor? Please provide it in clear text.

Regards,

Miguel Aikens

Created on Jul 26, 2022 1:05:46 PM by  Miguel Aikens [Paessler Technical Support]




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.