PowerShell - Lists UDP and TCP ports with process using them
- Jon Boyette
- Jan 10, 2022
- 1 min read
Save as a .ps1, prompts for server name, Lists to screen all TCP and UDP ports, listening and bound with related process(es)
$a = Read-Host "Enter ServerName to Discover TCP/UDP Ports"
$nets = netstat -bano | select-string 'LISTENING|UDP'; foreach ($n in $nets) { $p = $n -replace ' +',' '; $nar = $p.Split(' '); $pname = $(Get-Process -id $nar[-1]).ProcessName; $n -replace "$($nar[-1])","$($ppath) $($pname)"; }
Comments