Friday, June 1, 2012

Use PowerShell to check if a port is open

Just a little something useful a came across today. Was troubleshooting some code a customer had developed that was authenticating to an ASP.NET membership database on their network. It was working on their development server but stopped working once it got deployed to their staging server. SQL Server was supposed to be listening on a non-standard port and Telnet wasn’t installed to try and open a connection to test that way. I ran across this PowerShell command that essentially does the same thing.

(new-object Net.Sockets.TcpClient).Connect("servername", 1434)
All you need to supply is the server name or IP and the port number. If you don’t end up with an error the port should be open and if you do, that is a good indication it is closed.