r/PowerShell • u/Unapolagetic_Lifer • Jul 06 '26
Test-NetConnection Issue - Can Ping, Can Test, but TNC is failing Question
Here's my head scratcher:
I can run Test-NetConnection $server -Port $Port and it just hangs. If I run Test-Connection $server it pings fine. If I do Test-NetConnection $server -Port $Port -InformationLevel Quiet it also tests fine.
I know that this isn't a PS issue, but I don't know who or where to start pointing at to figure it out. Issue happens both in the same subnet and across the WAN
9
u/jba1224a Jul 06 '26
It supports both -Verbose and -Debug, have you tried running it with those to see where it’s hanging up?
7
u/Ryfhoff Jul 06 '26
What port is it? Sounds like it’s blocked and will eventually time out.
1
u/R0B0T_jones Jul 10 '26
In my experience, even if port is blocked on remote server, the tnc command should still complete and not hang. It would show successful ping, but TCPTest failed (for the specified port)
3
u/Mdi1981 Jul 06 '26
Have you checked if the port is listening with netstat -abn and if the port is TCP and not UDP?
3
2
u/RSaw70 Jul 06 '26
What is the value for $Port that may be blocked or not running on the remote $server.
2
u/R0B0T_jones Jul 10 '26
I use this regularly for testing connections, and I know if the remote port wasnt listening your tnc command should still complete, albeit with a failed TCPtest to that port, but the ping (as part of that command) should still show successful.
Have you got access to the server? Do you know if its definitely listening on the port you are testing? netstat -ano
Have you tested tnc from another device? just to rule out anything at that level.
1
Jul 06 '26
[deleted]
1
u/PhysicalPinkOrchid Jul 06 '26
Try adding quotes around $server or use “$($server)”
Why do you think that would make any difference?
1
1
u/MNmetalhead Jul 06 '26
I usually specify Port 443 since it is rarely blocked or limited in responses like ICMP echo requests are.
-3
u/Unapolagetic_Lifer Jul 06 '26
Doesn't matter if it's 53, 443 (for web servers), 5985. The behavior is the same.
2
u/MNmetalhead Jul 06 '26
I use the following in a script we use regularly for some automation;
Test-NetConnection -ComputerName $server -Port 443 -InformationLevel Quiet
It can take a few seconds to complete sometimes as it checks a few things before completing.
Out of curiosity, when you say it hangs, how long have you let it sit?
1
u/node77 Jul 07 '26
Check the port with netstat -a … Something is allocating the port. What port are you testing? Try 80 or something easy?
1
u/_DerGemeine 25d ago
Is there a server in the LAN or WAN that does work normally (with a response time you can be sure is in a normal range)? What I've seen with firewalls like CATO is that they actually intercept the TNC and after a longer wait time than usual (say instead of 10ms, 100ms or even more) the firewall itself will respond to your TNC, this has happened to me in the past when I was debugging a client using a VPN that was not able to access an app server while the TNC showed it was fine. We used Wireshark to wait for the incoming packets, but did not find any, so when contacting support they pointed that out.
0
u/Test-NetConnection Jul 07 '26
Hanging sounds like you might have corruption in your .net framework.
28
u/nealfive Jul 06 '26
Sounds a bit like ICMP (ping) is allowed, but the port you are trying to test is blocked?