Testing Port Connectivity with Powershell

From Windows Server 2012 R2 (Powershell V4) and above you can use the test-netconnection command in Powershell to test port connectivity

The syntax is:-

test-netconnection <servername> -port <port number>

example:-

test-netconnection myserver -port 5723 

If you are on a version of windows server below Windows Server 2012 R2 you can run the following (change scom02.opsmgr.net to the name of your server):-

$server=”scom2.opsmgr.net”;
$ip=([System.Net.Dns]::GetHostAddresses($server)).IPAddressToString;
$tcp=New-Object net.sockets.tcpclient;$tcp.Connect($server,5723);
$out=$tcp.Connected;
write-host “`nPort 5723 test result for ($server) on IP ($ip) : ($out)”

This entry was posted in Powershell for SCOM and tagged , , , , , , , , , , , , , , , , , , . Bookmark the permalink.

Leave a comment