Advertisement
guyrleech

Show local network port usage

Feb 23rd, 2021
1,278
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. [hashtable]$processes = @{}
  2.  
  3. Get-Process | ForEach-Object { $processes.Add( $_.Id , $_ )} ## build dictionary/hashtable keyed on the PID for fast lookup
  4.  
  5. Get-NetTCPConnection |  Where-Object { ( $_.LocalAddress -eq "0.0.0.0" -or $_.LocalAddress -eq "127.0.0.1" ) -and $_.State -ne "Bound" } |sort-object -property LocalPort|select-object -property LocalAddress,LocalPort,RemoteAddress,RemotePort,State,OwningProcess,@{n='Process';e={$processes[ [int]$_.OwningProcess ]|select-object -expandproperty name}}|format-table -auto
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement