Created
December 12, 2019 17:46
-
-
Save a5ync/ee6c2ba8e3decc107cf6edd9eaebaddb to your computer and use it in GitHub Desktop.
Logging netstat from powershell
This file contains hidden or 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
| $ipTracking="10.200.0.109" | |
| while(1) | |
| { | |
| $date=get-date -format "yyyy/MM/dd HH:mm:ss" | |
| $connections =(get-nettcpconnection -remoteaddress $ipTracking ` | |
| -ErrorAction SilentlyContinue ` | |
| | select-object -Property LocalAddress,LocalPort,RemoteAddress,RemotePort,State, ` | |
| @{name='Process';expression={(Get-Process -Id $_.OwningProcess).Name}},CreationTime ` | |
| | format-table -Autosize) ` | |
| | out-string | |
| Write-Host $date $connections | |
| Add-content -Path c:\repos\connections.log -Value "$date $connections" | |
| Start-Sleep -Seconds 10 | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment