简体   繁体   中英

PowerShell command to check the connection between IPaddress and port in Windows Server 2008 R2

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?

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.

您可以在此处查看NetStat工具的更多信息

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM