Having issues. When I run the following script on a system outside of PRTG, everything works as expected:
param ( [string] $UserName = "username!", [string] $Pass = "password!" ) $Pass = ConvertTo-SecureString $Pass -AsPlainText -Force $cred = New-Object Management.Automation.PSCredential ($UserName, $Pass) $R = Invoke-RestMethod -Uri "http://WEBSERVER" -Method Get -UseBasicParsing -Credential $cred | Select-Object "messages*"
The expected return looks like this:
messages_persistent : 0 messages_unacknowledged_ram : 0 messages_ready_ram : 0 messages_ram : 0 messages_unacknowledged_details : @{rate=0.6} messages_unacknowledged : 0 messages_ready_details : @{rate=0.0} messages_ready : 0 messages_details : @{rate=0.6} messages : 0
It returns as a PSObject.
When I run this same script in PRTG, I get the following error:
sensors\EXEXML\Get-ProdMessages.ps1:7 char:9 + $cred = New-Object Management.Automation.PSCredential ($UserName, $Pa ... + ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + CategoryInfo : InvalidOperation: (:) [New-Object], MethodExcept ion + FullyQualifiedErrorId : ConstructorInvokedThrowException,Microsoft.Power Shell.Commands.NewObjectCommand Invoke-RestMethod : {"error":"Unauthorized","reason":"\"Unauthorized\"\n"} At C:\Program Files (x86)\PRTG Network Monitor\custom sensors\EXEXML\Get-ProdMessages.ps1:9 char:6 + $R = Invoke-RestMethod -Uri "WEBSERVER ... + ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + CategoryInfo : InvalidOperation: (System.Net.HttpWebRequest:Htt pWebRequest) [Invoke-RestMethod], WebException + FullyQualifiedErrorId : WebCmdletWebResponseException,Microsoft.PowerShe ll.Commands.InvokeRestMethodCommand
What can I do to get this to work?
Add comment