Created
February 23, 2019 02:16
-
-
Save keithga/e7e2b8268df9616cba9546b4f1b7e953 to your computer and use it in GitHub Desktop.
network trace program
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
#Requires -RunAsAdministrator | |
<# | |
.Synopsis | |
Launch network trace | |
.DESCRIPTION | |
Launches network trace and displays a | |
.EXAMPLE | |
Example of how to use this cmdlet | |
.NOTES | |
ONly works on powershell.exe console. Will not work on Powershell_ISE.exe | |
#> | |
[cmdletbinding()] | |
param( | |
[string] $path = "c:\windows\temp\$env:computername NetTrace.etl", | |
[string[]] $NetShOptions = @( | |
'persistent=yes' | |
'capture=yes' | |
'maxSize=2048' | |
'fileMode=circular' | |
'correlation=no' | |
'perfMerge=yes' | |
'overwrite=yes' | |
) | |
) | |
if ( $Host.Name -ne 'ConsoleHost' ) { throw "only works from powershell.exe console, not from ISE" } | |
#region Launch netsh | |
write-verbose "launch NetSH.exe $NetShOptions TraceFile='$Path'" | |
& netsh.exe trace start $NetShOptions traceFile="$path" | |
#endregion | |
#region Display progress while NetSh.exe is running | |
write-verbose "display progress" | |
[console]::TreatControlCAsInput = $true | |
$start = [datetime]::now | |
while ( ! [console]::KeyAvailable ) { | |
$EllapsedTime = [datetime]::now.Subtract($start).tostring('d\.hh\:mm\:ss') | |
write-progress -Activity "Collecting Network Trace : Ellapsed Time: $EllapsedTime" -Status "Press Any Key to Exit" | |
} | |
write-verbose "All done, now cleanup..." | |
[console]::TreatControlCAsInput = $false | |
#endregion | |
#region Terminate netsh | |
write-verbose "Stop NetSh.exe" | |
& netsh.exe trace stop | write-output | |
#endregion | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment