Forum / Remote Desktop Manager - PowerShell Repository

Test if TCP connection works for each RDP item in RDM and if not then set status to "warning" + msg

  • Create an Issue
  • Cancel

# This Script reads first all RDP connections from RDM
# then runs a connection test on each single one with Net.Sockets.TcpClient($IP, 3389)
# if connection nok then --> set "status" field = Warning on RDP item in RDM with Warning msg "Keine Verbindung möglich"
# else (ok) -->
delete "status" field and Warning msg

$SessionList = Get-RDMSession | where {$_.Kind -eq "RDPConfigured"}
$results = @()

foreach ($session in $SessionList){

$result = "" | select Session,RDP
$result.session = $session

$IP = Get-RDM-Property $session.ID -Property Host

$socket = New-Object Net.Sockets.TcpClient($IP, 3389)
if($socket -eq $null){
$result.RDP = $false
$result.RDP = $true
write-output ("$IP 'OK'")
Set-RDM-Property -NoRefresh -ID $ -Property "Status" -Value ''
Set-RDM-Property -NoRefresh -ID $ -Property "StatusMessage" -Value ''
$result.RDP = $false
write-output ("$IP '!!!NOK!!!'")
# $session.MetaInformation.CustomField3Value= "NO Connection"
Set-RDM-Property -NoRefresh -ID $ -Property "Status" -Value '{123A44CB-7EDC-4ecb-926B-031793668148}'
Set-RDM-Property -NoRefresh -ID $ -Property "StatusMessage" -Value 'Keine Verbindung möglich'

return $results
edited by on 5/13/2015
edited by on 5/26/2015

Clock5 yrs

Thank you for sharing, this is a good strategy if using our monitoring feature on too many hosts slows down RDM.

If you store this script in RDM, you can even use the task scheduler and invoke it by using the command line as seen in the advanced tab of the entry.

Maurice Côté


Clock5 yrs