Answered by:
Script to check RDP connection status

Question
-
Hi all,
Could anyone provide me a script to check whether multiple remote servers are able to RDP or not. I just want to check the connectivity status. I have checked with past threads available in form, but none has worked for me. Powershell or Batch or VBS scripts ... anything would be good....
I am not that much good at writing scripts.. So please help me.
Thanks in Advance..
Vinay..
- Edited by K Vinay Kumar Wednesday, September 17, 2014 3:53 PM
- Moved by Bill_Stewart Monday, October 20, 2014 5:39 PM This is not "scripts on demand"
Wednesday, September 17, 2014 5:37 AM
Answers
-
Here is a batch method:
@echo off
set Host=MyServer
set Port=3389
nc.exe -z %Host% %Port%
if %ErrorLevel% GTR 0 echo %Server% does not respond on port %Port%You can get nc.exe here.
- Proposed as answer by Mike Laughlin Wednesday, September 17, 2014 2:17 PM
- Marked as answer by Just Karl Tuesday, June 2, 2015 10:34 PM
Wednesday, September 17, 2014 5:51 AM -
function Test-RDPEndpoint{ Param($Computer) $tcp=New-Object System.Net.Sockets.TcpClient Try{ $tcp.Connect($computer,3389) $tcp.Close() Write-Host 'Cpnnected' -fore green } Catch{ Write-Host 'Connect failed' -fore green } } Test-RDPEndPoint -Computer omega
¯\_(ツ)_/¯
- Edited by jrv Wednesday, September 17, 2014 8:17 AM
- Proposed as answer by Mike Laughlin Wednesday, September 17, 2014 2:18 PM
- Marked as answer by Just Karl Tuesday, June 2, 2015 10:33 PM
Wednesday, September 17, 2014 8:17 AM
All replies
-
Here is a batch method:
@echo off
set Host=MyServer
set Port=3389
nc.exe -z %Host% %Port%
if %ErrorLevel% GTR 0 echo %Server% does not respond on port %Port%You can get nc.exe here.
- Proposed as answer by Mike Laughlin Wednesday, September 17, 2014 2:17 PM
- Marked as answer by Just Karl Tuesday, June 2, 2015 10:34 PM
Wednesday, September 17, 2014 5:51 AM -
function Test-RDPEndpoint{ Param($Computer) $tcp=New-Object System.Net.Sockets.TcpClient Try{ $tcp.Connect($computer,3389) $tcp.Close() Write-Host 'Cpnnected' -fore green } Catch{ Write-Host 'Connect failed' -fore green } } Test-RDPEndPoint -Computer omega
¯\_(ツ)_/¯
- Edited by jrv Wednesday, September 17, 2014 8:17 AM
- Proposed as answer by Mike Laughlin Wednesday, September 17, 2014 2:18 PM
- Marked as answer by Just Karl Tuesday, June 2, 2015 10:33 PM
Wednesday, September 17, 2014 8:17 AM -
Thanks Frederik for your response.... but I couldn't implement this batch since nc.exe is discarded by antivirus in our servers.
Is there any other way to get it done.
Wednesday, September 17, 2014 3:41 PM -
Thanks jrv for your response. could you please tell me which language is it and how to execute it.
Is it PERL?? If yes, I am a newbie to that area. Please explain how to execute it.
- Edited by K Vinay Kumar Wednesday, September 17, 2014 3:52 PM
Wednesday, September 17, 2014 3:46 PM -
PowerShell - look at Learn link at top of page to get instructions
You can also use PortQry from MS in a batch file and parse the output
http://www.microsoft.com/en-us/download/details.aspx?id=17148
Yes - most copies of NC on the iNet are infected.
¯\_(ツ)_/¯
Wednesday, September 17, 2014 3:49 PM -
Hi Vinay,
Do you have the server names in a text file or do you want to query AD for the servers you wish to check their RDP status? Before I commence working on the script, I will like to be sure that I understand what you require - You want to check whether a server is enabled to accept Remote desktop connections or not, I believe?
Saturday, September 20, 2014 5:18 AM -
Run this script on one of the servers:
Get-Wmiobject -Class Win32_Terminal -Property *
It should return a number of information including, fEnableTerminal. For servers that have RDP enabled, fEnableTerminal should be 1, for the servers with RDP not enabled, fEnableTerminal should be 0.
Once you can confirm that this is the case, I will provide the full script to run this on multiple servers with input from AD query of text file
Saturday, September 20, 2014 6:08 AM -
Run this script on one of the servers:
Get-Wmiobject -Class Win32_Terminal -Property *
It should return a number of information including, fEnableTerminal. For servers that have RDP enabled, fEnableTerminal should be 1, for the servers with RDP not enabled, fEnableTerminal should be 0.
Once you can confirm that this is the case, I will provide the full script to run this on multiple servers with input from AD query of text file
That still won't tell you if the TS is accessible. PortQry or Net Tcp are the fastest and easiest ways to do this.
Your code also only orks on WS2008R2 and later but, s posted, ill not work on any system. Have you actually tried it?
The other bigger issue is that the Win32_Terminal class will always return enabled on any server even if the terminal server is inaccessible and even if it is in Admin mode. All Servers since 2003 have Terminal Server running by default but not in Terminal Server mode.
PortQry to 3389 will tell us that the TS is alive and available. Win32_Terminal will report enabled even if the service is stopped.
Win32_Terminal is only useful to admins and PortQry can be used by anyone.
The above PowerShell code can be run on any system instead of installing PortQry or other software.
The original question was "Check RDP connection". RDP is available on all systems since XP. The Win32_Terminal class is only available on Server class machines and it does not check to see if the RDP connection is available.
¯\_(ツ)_/¯
- Edited by jrv Saturday, September 20, 2014 6:44 AM
Saturday, September 20, 2014 6:40 AM -
Victor - note also that "-property *" is unnecessary for WMI in PowerShell as it is the default. We usually use the property argument to reduce the number of properties returned.
Try testing with varios servers and workstations from Xp on up and you will begin to see why it is not a very useful solution. It also is not usefule over the Internet which is where we usually ant to check the RDP availability.
Both PortQry and Net TCP can also tell us what service responds and can probe the firewall to determine if the port is open/close or filtered.
In a domain or local subnet an administrator can use Win32_Terminal to determine the mode the TS is in and if it is running. If it is only in Aministrative mode there will be no status so we will not know if RDP is available.
If you are looking for a comprehensive test of TS I recommend using both WMI and the Net TCP classes along with a few other WMI classes. Yu can then report on the installed and enabled state of TS as well as the availability of RDP and ICA or other installed protocol handlers.
When most users ask about RDP they just want to ping it to see if it is available for connecting.
¯\_(ツ)_/¯
Saturday, September 20, 2014 7:01 AM