Skip to content

Instantly share code, notes, and snippets.

@scivision
Created February 7, 2024 17:04
Show Gist options
  • Save scivision/03e69c1e6fca08a21f5cfb5af03c1526 to your computer and use it in GitHub Desktop.
Save scivision/03e69c1e6fca08a21f5cfb5af03c1526 to your computer and use it in GitHub Desktop.
PowerShell list ports that programs are listening on
# copied from https://superuser.com/a/1808022
$procs = Get-Process
$ports = netstat -ano
$ports[4..$ports.length] |
# First column comes back empty, so we set to "ProcessName" as a placeholder for later
ConvertFrom-String -PropertyNames ProcessName,Proto,Local,Remote,State,PID |
where State -eq 'LISTENING' |
foreach {
$_.ProcessName = ($procs | where ID -eq $_.PID).ProcessName
$_
} |
Format-Table
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment