Skip to content

Commit 2fa708b

Browse files
committed
Add Force switch to Invoke-DiscoveryProtocolCapture
Force will stop and remove any existing NetEventSessions.
1 parent da128f3 commit 2fa708b

File tree

1 file changed

+14
-1
lines changed

1 file changed

+14
-1
lines changed

PSDiscoveryProtocol/PSDiscoveryProtocol.psm1

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -148,7 +148,10 @@ function Invoke-DiscoveryProtocolCapture {
148148
[String]$Type,
149149

150150
[Parameter()]
151-
[switch]$NoCleanup
151+
[switch]$NoCleanup,
152+
153+
[Parameter()]
154+
[switch]$Force
152155
)
153156

154157
begin {
@@ -195,6 +198,16 @@ function Invoke-DiscoveryProtocolCapture {
195198

196199
if ($Adapter) {
197200
$SessionName = 'Capture-{0}' -f (Get-Date).ToString('s')
201+
202+
if ($Force.IsPresent) {
203+
Get-NetEventSession -CimSession $CimSession | ForEach-Object {
204+
if ($_.SessionStatus -eq 'Running') {
205+
$_ | Stop-NetEventSession -CimSession $CimSession
206+
}
207+
$_ | Remove-NetEventSession -CimSession $CimSession
208+
}
209+
}
210+
198211
New-NetEventSession -Name $SessionName -LocalFilePath $ETLFilePath -CaptureMode SaveToFile -CimSession $CimSession | Out-Null
199212

200213
$LinkLayerAddress = switch ($Type) {

0 commit comments

Comments
 (0)