This might take you < 1 minutes to read.

In Windows 2012R2 and Windows 8.1 there is a command “Test-NetConnect” which tests a TCP port. That is a life saver. To be able to do that in Windows 2012 I created a small function.

What it does is to take two parameters. first is an IPaddress and the second one is the tcp-port.

Then it connects to the tcp-socket and will prompt with a result, if it was able to connect or not.

Function test-IP-Port {
	param (
		[ValidateScript({$_ -match [IPAddress]$_ })]  
        [String] $Ipaddress,
		[Int] $Port
	$netSocket = New-Object Net.Sockets.TcpClient
        "Port $Port on $IPAddress is listening."
        "Port $Port is closed on $IPAddress is closed. "


Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.