PowerShell / PowerShell

PowerShell for every system!
https://microsoft.com/PowerShell
MIT License
43.55k stars 7.06k forks source link

Test-NetConnection: Show specific error when connection to a TCP port could not be established #21569

Closed maximilianpalm closed 1 week ago

maximilianpalm commented 2 weeks ago

Summary of the new feature / enhancement

As a user, I want Test-NetConnection to print the specific error that happened during a connection attempt, so that I can narrow down the source or type of connection issue.

Currently, when checking if a TCP port is open on a remote machine using Test-NetConnection, I can see if the connection was established successfully or not. If it wasn't, I don't get information on the kind of error that happened. It would be useful to know whether the connection attempt failed e.g. because of a timeout or because the connection was refused by the target machine. The former might indicate a firewall is dropping packets while the latter one might suggest that the application isn't running on the target machine. This enables me locate the issue easier and faster.

I'd hope to see this implemented in Test-NetConnection, because for me this is by far the most common use case for this cmdlet. Otherwise, I have to resort to other tools or more complicated scripts just to get a piece of information that Test-NetConnection already has. It just needs to print it for the user.

Proposed technical implementation details (optional)

Usage Example (current state):

Test-NetConnection somehostname -Port 1433 -InformationLevel Detailed
WARNING: TCP connect to (10.0.1.201 : 1433) failed

ComputerName            : somehostname
RemoteAddress           : 10.0.1.201
RemotePort              : 1433
NameResolutionResults   : 10.0.1.201
MatchingIPsecRules      :
NetworkIsolationContext : Private Network
IsAdmin                 : False
InterfaceAlias          : Dialog
SourceAddress           : 10.0.2.38
NetRoute (NextHop)      : 10.0.2.35
PingSucceeded           : True
PingReplyDetails (RTT)  : 0 ms
TcpTestSucceeded        : False

Usage Example (desired state, see warning and additional line at the end):

Test-NetConnection somehostname -Port 1433 -InformationLevel Detailed
WARNING: TCP connect to (10.0.1.201 : 1433) failed, error: "connection refused"

ComputerName            : somehostname
RemoteAddress           : 10.0.1.201
RemotePort              : 1433
NameResolutionResults   : 10.0.1.201
MatchingIPsecRules      :
NetworkIsolationContext : Private Network
IsAdmin                 : False
InterfaceAlias          : Dialog
SourceAddress           : 10.0.2.38
NetRoute (NextHop)      : 10.0.2.35
PingSucceeded           : True
PingReplyDetails (RTT)  : 0 ms
TcpTestSucceeded        : False
TcpTestErrorMessage     : Connection refused
StevenBucher98 commented 1 week ago

Thanks for the issue! I believe this module comes with Windows/windows PowerShell, this repo is only for PowerShell 7 issues and modules that are inbox with that specific version. I suggest submitting feedback on this via the product feedback hub, https://support.microsoft.com/en-us/windows/send-feedback-to-microsoft-with-the-feedback-hub-app-f59187f8-8739-22d6-ba93-f66612949332

Send feedback to Microsoft with the Feedback Hub app - Microsoft Support
Learn how to use Feedback Hub to report problems or send suggestions to Microsoft.
microsoft-github-policy-service[bot] commented 1 week ago

This issue has been marked as external and has not had any activity for 1 day. It has been be closed for housekeeping purposes.

microsoft-github-policy-service[bot] commented 1 week ago

📣 Hey @maximilianpalm, how did we do? We would love to hear your feedback with the link below! 🗣️

🔗 https://aka.ms/PSRepoFeedback

Microsoft Forms