Test if TCP connection works for each RDP item in RDM and if not then set status to "warning" + msg
# 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
try{
$socket = New-Object Net.Sockets.TcpClient($IP, 3389)
if($socket -eq $null){
$result.RDP = $false
}else{
$result.RDP = $true
$socket.close()
write-output ("$IP 'OK'")
Set-RDM-Property -NoRefresh -ID $session.id -Property "Status" -Value ''
Set-RDM-Property -NoRefresh -ID $session.id -Property "StatusMessage" -Value ''
}
}
catch{
$result.RDP = $false
write-output ("$IP '!!!NOK!!!'")
# $session.MetaInformation.CustomField3Value= "NO Connection"
Set-RDM-Property -NoRefresh -ID $session.id -Property "Status" -Value '{123A44CB-7EDC-4ecb-926B-031793668148}'
Set-RDM-Property -NoRefresh -ID $session.id -Property "StatusMessage" -Value 'Keine Verbindung möglich'
}
}
return $results
edited by Steffen.Rietzschel.ext@siemens.com on 5/13/2015
edited by Steffen.Rietzschel.ext@siemens.com on 5/26/2015
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