Join listening TCP ports to their owning process details
Build a paste-ready command, then review its compatibility and effects before running it.
Get-NetTCPConnection -State Listen | Sort-Object LocalPort | ForEach-Object { $p=Get-Process -Id $_.OwningProcess -ErrorAction SilentlyContinue; [pscustomobject]@{Address=$_.LocalAddress;Port=$_.LocalPort;PID=$_.OwningProcess;Process=$p.ProcessName;Path=$p.Path} } | Format-Table -AutoSizeread-onlyno known side effects Compatibility
WindowsVerified for Windows using powershell syntax.
Operational knowledgereview due 2027-01-19
RequirementsGet-NetTCPConnectionGet-NetTCPConnection must be installed and available on PATH.
Version supportGet-NetTCPConnection Current supported releasesVerified for windows using powershell syntax; consult compatibility notes for platform-specific differences.
Expected signalsAddress Port PID Process PathRepresentative successful output; values vary with the selected target and system state.
Known errorsGet-NetTCPConnection: command not foundGet-NetTCPConnection is missing or is not available on PATH.
VerifyGet-NetTCPConnection -State Listen | Sort-Object LocalPort | ForEach-Object { $p=Get-Process -Id $_.OwningProcess -ErrorAction SilentlyContinue; [pscustomobject]@{Address=$_.LocalAddress;Port=$_.LocalPort;PID=$_.OwningProcess;Process=$p.ProcessName;Path=$p.Path} } | Format-Table -AutoSizeThe output matches the expected target and exits without an error.Rollback noteNot required: this command is read-only and does not change system state.
Command breakdown
01Get-NetTCPConnectionCommandRuns the Get-NetTCPConnection stage of this one-liner.
02-StateOptionConfigures Get-NetTCPConnection with the -State option.
03ListenArgumentPasses Listen to Get-NetTCPConnection.
04|PipelinePasses the output on the left to the command on the right.
05Sort-ObjectCommandRuns the Sort-Object stage of this one-liner.
06LocalPortArgumentPasses LocalPort to Sort-Object.
07|PipelinePasses the output on the left to the command on the right.
08ForEach-ObjectCommandRuns the ForEach-Object stage of this one-liner.
09{ArgumentPasses { to ForEach-Object.
10$p=Get-ProcessVariableExpands a value from the current shell environment or loop.
11-IdOptionConfigures ForEach-Object with the -Id option.
12$_.OwningProcessVariableExpands a value from the current shell environment or loop.
13-ErrorActionOptionConfigures ForEach-Object with the -ErrorAction option.
14SilentlyContinueArgumentPasses SilentlyContinue to ForEach-Object.
15;Command separatorEnds this shell statement before the next one begins.
16[pscustomobject]@{Address=$_.LocalAddressCommandRuns the [pscustomobject]@{Address=$_.LocalAddress stage of this one-liner.
17;Command separatorEnds this shell statement before the next one begins.
18Port=$_.LocalPortVariable assignmentSets a value used by the commands that follow.
19;Command separatorEnds this shell statement before the next one begins.
20PID=$_.OwningProcessVariable assignmentSets a value used by the commands that follow.
21;Command separatorEnds this shell statement before the next one begins.
22Process=$p.ProcessNameVariable assignmentSets a value used by the commands that follow.
23;Command separatorEnds this shell statement before the next one begins.
24Path=$p.Path}Variable assignmentSets a value used by the commands that follow.
25}CommandRuns the } stage of this one-liner.
26|PipelinePasses the output on the left to the command on the right.
27Format-TableCommandRuns the Format-Table stage of this one-liner.
28-AutoSizeOptionConfigures Format-Table with the -AutoSize option.
This advanced community-curated one-liner combines several stages. Review every option and placeholder before running it.
Example input
Get-NetTCPConnection -State Listen | Sort-Object LocalPort | ForEach-Object { $p=Get-Process -Id $_.OwningProcess -ErrorAction SilentlyContinue; [pscustomobject]@{Address=$_.LocalAddress;Port=$_.LocalPort;PID=$_.OwningProcess;Process=$p.ProcessName;Path=$p.Path} } | Format-Table -AutoSize
Example output
Address Port PID Process Path
------- ---- --- ------- ----
0.0.0.0 135 1120 svchost C:\Windows\System32\svchost.exe
0.0.0.0 3389 1468 svchost C:\Windows\System32\svchost.exe
Illustrative output — exact values vary by system and data.
Official sources