Hello - I've written a powershell script for this but I need a little help tweaking the output. I need to monitor the "Connections Allowed" status of our Remote Desktop session host servers. The script appears to be working when I run it manually, but no matter what the actual data is in the XML output, the sensor always shows a status of 0. What am I missing here?

Here's some sample output:

C:\Program Files (x86)\PRTG Network Monitor\Custom Sensors\EXEXML>powershell.exe -command .\PRTG_RDSH_Session_Connections_Allowed.ps1 -RDSH_Server "rdsh1.domain.com"
<prtg>
                <result>
                    <channel>New Connections</channel>
                    <unit>Custom</unit>
                    <CustomUnit>Status</CustomUnit>
                    <value>2</value>
                </result>
    <text>OK</text>
</prtg>

C:\Program Files (x86)\PRTG Network Monitor\Custom Sensors\EXEXML>powershell.exe -command .\PRTG_RDSH_Session_Connections_Allowed.ps1 -RDSH_Server "rdsh2.domain.com"
<prtg>
                <result>
                    <channel>New Connections</channel>
                    <unit>Custom</unit>
                    <CustomUnit>Status</CustomUnit>
                    <value>0</value>
                </result>
    <text>OK</text>
</prtg>

Here's the script itself:

param(
[string]$RDSH_Server
)

#variables

$name = 'New Connections'
$unit = "Custom"
$customUnit = "Status"
$mode = "Absolute"
$warning = 0
$float = 1

$ConnectionsEnabled=Get-RDSessionHost -ConnectionBroker rdcb.domain.com -CollectionName "Apps - General" | where {$_.SessionHost -eq $RDSH_Server} | Select NewConnectionAllowed -ExpandProperty NewConnectionAllowed
if ($ConnectionsEnabled -eq "Yes") {$ConnectionsEnabledInt=0}
if ($ConnectionsEnabled -eq "NotUntilReboot") {$ConnectionsEnabledInt=1}
if ($ConnectionsEnabled -eq "No") {$ConnectionsEnabledInt=2}

#Create xml for sensor
$xml = @"
<prtg>

"@


#Main XML body for result
$xml += @"
                <result>
                    <channel>$name</channel>                    
                    <unit>$unit</unit>
                    <CustomUnit>$customUnit</CustomUnit>
                    <value>$ConnectionsEnabledInt</value>
                </result>

"@
#Text for sensor
$xml += @"
    <text>OK</text>

"@
#add /prtg to close out the xml.
 $xml += @"
</prtg>

"@           
 #output the XML
 $xml

Article Comments

Can you please enable the write result to disk option in the settings of the sensor and post that result here?


Nov, 2015 - Permalink