Hi,

I would like to get the result of this powershell in to a PRTG sensor. it just outputs a integer.

(Get-Counter @("\Terminal Service Gateway\Current connections") -ComputerName "127.0.0.1").CounterSamples.CookedValue

When I put it in a .ps1 and add it to the probe Custom sensors EXE folder and use it in a sensore it just says:

Response not well-formed: "(The specified object was not found on the computer. )" (code: PE132)

While when I run it in powershell on the target server (RDG) it outputs a number

Anyone an idea?


Article Comments

Hello Jurgen,

Thank you for your message.

According to your message, the command you are using is performed on the probe server and not on the target one, hence the error message you get. Therefore, I recommend to execute the command remotely by using the following:

param (
    [string] $target,
    [string] $winuser,
    [string] $winpass
)

$credentials = New-Object System.Management.Automation.PSCredential ($winuser, (ConvertTo-SecureString $winpass -AsPlainText -Force))

try {
    $counter = Invoke-Command -ComputerName $target -Credential $credentials -Scriptblock {
        (Get-Counter @("\Terminal Service Gateway\Current connections") -ComputerName "127.0.0.1").CounterSamples.CookedValue
    }

    Write-Output "$($counter):Ok"
    Exit 0
}
catch {
    Write-Output "-1:$($_.exception.message) At line : $($_.InvocationInfo.ScriptLineNumber)"
    Exit 1
}

To use it, copy the content within the EXE folder and create a new EXE/Script sensor. Then, add the following in the field Parameters:

-target "%host" -winuser "%windowsuser" -winpass "%windowspassword"

Make sure that the credentials defined in the parent device settings under Credentials for Windows devices have enough rights to execute the command on the target device.

Please, note that we do not provide official support for customizations. The code above is provided as is (not tested) and might need to be modified to work properly.

Regards.


Apr, 2022 - Permalink