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.
Add comment