Created
March 30, 2017 14:26
-
-
Save wboevink/93c21b9c146ab376340559e827520d68 to your computer and use it in GitHub Desktop.
What's running on port ...
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
$proc = @{}; | |
Get-Process | ForEach-Object { $proc.Add($_.Id, $_) }; | |
netstat -aon | Select-String "\s*([^\s]+)\s+([^\s]+):([^\s]+)\s+([^\s]+):([^\s]+)\s+([^\s]+)?\s+([^\s]+)" | ForEach-Object { | |
$g = $_.Matches[0].Groups; | |
New-Object PSObject | | |
Add-Member @{ Protocol = $g[1].Value } -PassThru | | |
Add-Member @{ LocalAddress = $g[2].Value } -PassThru | | |
Add-Member @{ LocalPort = [int]$g[3].Value } -PassThru | | |
Add-Member @{ RemoteAddress = $g[4].Value } -PassThru | | |
Add-Member @{ RemotePort = $g[5].Value } -PassThru | | |
Add-Member @{ State = $g[6].Value } -PassThru | | |
Add-Member @{ PID = [int]$g[7].Value } -PassThru | | |
Add-Member @{ Process = $proc[[int]$g[7].Value] } -PassThru; | |
#} | Format-Table Protocol,LocalAddress,LocalPort,RemoteAddress,RemotePort,State -GroupBy @{Name='Process';Expression={$p=$_.Process;@{$True=$p.ProcessName; $False=$p.MainModule.FileName}[$p.MainModule -eq $Null] + ' PID: ' + $p.Id}} -AutoSize | |
} | Sort-Object PID | Out-GridView |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment