Command library / Test-NetConnection
Test-NetConnection
Test connectivity to a host and TCP port
PowerShell's all-in-one connectivity check: ping, TCP port test and route tracing in a single cmdlet. It returns an object (TcpTestSucceeded, RemotePort …) instead of text, so it composes well in scripts. PowerShell names and parameters are case-insensitive, and `tnc` is a built-in alias.
Practice Test-NetConnectionUsage
Options and flags
-ComputerName, -CN, -RemoteAddressHOSTtarget host name or IP (first positional parameter)
-Port, -RemotePortPORTTCP port to test
-CommonTCPPortNAMEshortcut for a well-known port: HTTP, RDP, SMB or WINRM
-InformationLevelLEVELQuiet returns just True/False; Detailed returns everything
-TraceRoutealso trace the network path to the target
Examples
Test-NetConnection 10.0.0.5 -Port 445Is SMB reachable on 10.0.0.5?
Test-NetConnection 10.0.0.5 -Port 3389 -InformationLevel QuietReturns only True or False — ideal for scripts.
Test-NetConnection intranet.local -CommonTCPPort HTTPTest HTTP (port 80) using the shortcut.
Test-NetConnection 10.0.0.5 -TraceRoutePing plus the hop-by-hop path.
Common mistakes
-Port needs a port number right after it.