0

I am working with PowerShell scripting on Windows Server 2012 R2. I was checking on the test connection of a machine with port. The following PowerShell command is working:

Test-NetConnection localhost -Port 445

This command along with -InformationLevel was returning either TRUE or FALSE depending on the result. This is exactly what I wanted.

I need to run the same check on Windows Server 2008 R2. I understood that Test-NetConnection command will not work on Server 2008. I couldn't find any other commands to check the connection between machineIP and port and return whether TRUE or FALSE. Can anyone please suggest an alternative PowerShell command for this?

BenH
  • 9,766
  • 1
  • 22
  • 35
Deepu
  • 29
  • 1
  • 7
  • 1
    Possible duplicate of [How to check Network port access and display useful message?](http://stackoverflow.com/questions/9566052/how-to-check-network-port-access-and-display-useful-message) – TessellatingHeckler Feb 07 '17 at 18:35

2 Answers2

0

Here is a script from TechNet Script Center from Boe Prox.

There are many variants out there that make use of the System.Net.Sockets.TcpClient and System.Net.Sockets.UdpClient .Net classes using either the Connect or BeginConnect methods.

BenH
  • 9,766
  • 1
  • 22
  • 35
  • I wanted the check IP address connection with the port. So I have done the following and it worked. $tcpobject = new-Object system.Net.Sockets.TcpClient $connect = $tcpobject.BeginConnect($computer,$port,$null,$null) #Configure timeout before quitting $wait = $connect.AsyncWaitHandle.WaitOne(1000,$false) Check [here](https://social.technet.microsoft.com/Forums/windowsserver/en-US/37b3fc73-4c91-4a26-bd75-4156bcb96cce/how-to-controll-slow-response-times-for-negative-when-using-tcpobject-newobject?forum=winserverpowershell) for the full answer – Deepu Feb 09 '17 at 08:55
0

You can NetStat Tool Read More about NetStat here

Ajay Pawar
  • 179
  • 6