Created
February 7, 2024 17:04
-
-
Save scivision/03e69c1e6fca08a21f5cfb5af03c1526 to your computer and use it in GitHub Desktop.
PowerShell list ports that programs are listening on
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# 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