PowerShell

PowerShell: Check open/closed ports with Test-NetConnection

The more I am playing with it, the more I like it: Test-NetConnection. Test-NetConnection views information of a connection. What can we do with it?

Ping

If the computername was not specified, the default value is internetbeacon.msedge.net.

Test-NetConnection

1.PNG

Let´s specify an address for the remote host.

2.PNG

Happy to see that sid-500.com is responding much faster than the beacon thing. 😉

Test HTTP Connections

Is it possbile to establish a connection to sid-500.com with HTTP?

Test-NetConnection www.sid-500.com -CommonTCPPort HTTP

1.PNG

Yes, it is. And what about HTTPS?

Test-NetConnection www.sid-500.com -Port 443

4.PNG

Test RDP Connections

Well, my blog is working. Hopefully my blog cannot be reached via Remote Desktop (RDP). Good to see that it is not so.

Test-NetConnection www.sid-500.com -CommonTCPPort RDP

5.PNG

Running Test-Connection with tracert / traceroute

Traceroute traces the route of packets to a destination host. You can do the same with Test-NetConnection.

Test-NetConnection www.sid-500.com -TraceRoute

6.PNG

Running in Quiet Mode

Be Quiet. Show me only whether the host is reachable or not.

Test-NetConnection www.sid-500.com -InformationLevel Quiet

7.PNG

Running in Detailed Mode

To get more out of Test-Connection run it in Detailed Mode. Pay attention to the additional information about DNS Name Resolution and the Next Hop Address.

Test-NetConnection www.sid-500.com -InformationLevel Detailed

8.png

Remote Computers

What about Remote Computers? Can client001 establish a connection to dc01 via DNS? No need for logging on client001. Simply run a remote command:

Invoke-Command -ComputerName client001 {Test-NetConnection dc01 -Port 53 -InformationLevel Quiet}

Unbenannt.PNG

Yes, client001 can establish a connection to dc01 via DNS.

Conclusion

Hope this is helpful. The “smaller” version is Test-Connection: The modern version of ping: Test-Connection.

Or find out the IP-Address of the default gateway by reading the routing table: PowerShell: Testing the connectivity to the Default Gateway on localhost and Remote Hosts by reading the Routing Table

Categories: PowerShell

Tagged as: ,

17 replies »

  1. Hello Patrick,

    How can I get Test-netConnection for failed connection to email only when TCPTestSucceded = False.

    I tried -eq & – ne options but having no luck

    Bruce

    Like

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

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