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

RDG Remote Desktop Gateway User Count

Votes:

0

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?

powershell rdg rds

Created on Mar 30, 2022 1:43:25 AM



1 Reply

Votes:

0

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.

Created on Apr 1, 2022 7:42:33 AM by  Florian Lesage [Paessler Support]

Last change on Apr 1, 2022 7:43:28 AM by  Florian Lesage [Paessler 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.