用 Get-NetTCPConnection 列出监听端口和占用进程
netstat 的 PowerShell 原生替代品:按状态、端口、进程过滤连接,输出可直接管道处理而不用解析文本。
运行 `Get-NetTCPConnection -State Listen` 列出所有已绑定的 TCP 端口,再用 OwningProcess 配合 Get-Process 找到进程名。
01命令
命令
$ Get-NetTCPConnection -State Listen | Select-Object LocalAddress, LocalPort, OwningProcess02作用说明
与 netstat -ano 不同,Get-NetTCPConnection 返回真正的对象,可以直接作为参数过滤:`-LocalPort 443`、`-RemoteAddress 10.0.0.5`、`-State Established` 都行。每个对象带有 OwningProcess 属性,用 `(Get-Process -Id $_.OwningProcess).ProcessName` 即可解析出进程名。这是排查“8080 端口被谁占了”或审计服务器上异常监听的最干净方法。
03风险
04撤销
✓无需撤销——该命令不会改变持久状态。
05来源
- Get-NetTCPConnection - PowerShell依据: SS64 shows Get-NetTCPConnection usage with -State Listen and -LocalPort filters for listing bound ports.
- Get-NetTCPConnection | Microsoft Learn依据: Microsoft documents Get-NetTCPConnection parameters including -State with the Listen value and the OwningProcess property returned for each connection.
最后验证: 2026-09-17 · 分类: 网络