Advertisement
Guest User

Untitled

a guest
Oct 26th, 2014
132
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.06 KB | None | 0 0
  1. $proc = @{};
  2. Get-Process | ForEach-Object { $proc.Add($_.Id, $_) };
  3. netstat -aon | Select-String "s*([^s]+)s+([^s]+):([^s]+)s+([^s]+):([^s]+)s+([^s]+)?s+([^s]+)" | ForEach-Object {
  4. $g = $_.Matches[0].Groups;
  5. New-Object PSObject |
  6. Add-Member @{ Protocol = $g[1].Value } -PassThru |
  7. Add-Member @{ LocalAddress = $g[2].Value } -PassThru |
  8. Add-Member @{ LocalPort = [int]$g[3].Value } -PassThru |
  9. Add-Member @{ RemoteAddress = $g[4].Value } -PassThru |
  10. Add-Member @{ RemotePort = $g[5].Value } -PassThru |
  11. Add-Member @{ State = $g[6].Value } -PassThru |
  12. Add-Member @{ PID = [int]$g[7].Value } -PassThru |
  13. Add-Member @{ Process = $proc[[int]$g[7].Value] } -PassThru;
  14. #} | 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
  15. } | Sort-Object PID | Out-GridView
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement