|
30 | 30 | [Parameter(ParameterSetName = 'Start', Mandatory=$true)] |
31 | 31 | [switch] $Start, |
32 | 32 |
|
33 | | -# [Parameter(ParameterSetName = 'Start', Mandatory=$false)] |
34 | | -# [int] $StopAfter = [int]::Parse("0"), |
| 33 | + [Parameter(ParameterSetName = 'Start', Mandatory=$false)] |
| 34 | + [int] $StopAfter = [int]::Parse("0"), |
35 | 35 |
|
36 | 36 | [Parameter(ParameterSetName = 'Stop', Mandatory=$true)] |
37 | 37 | [switch] $Stop, |
|
61 | 61 |
|
62 | 62 | $global:EventSourceName = "MSSQL-SQLTrace" # For logging to the Application Event log |
63 | 63 | $global:INISettings = $null # set in ReadINIFile |
| 64 | +$global:StopAfterMinutes = 0 # set in StartTraces |
64 | 65 |
|
65 | 66 | $PathsToClean = @{} # for DeleteOldFiles |
66 | 67 |
|
@@ -95,7 +96,7 @@ LogRaw " |
95 | 96 | /_______ /\_____\ \_/|_______ \|____| |__| (____ / \___ >\___ > |
96 | 97 | \/ \__> \/ \/ \/ \/ |
97 | 98 |
|
98 | | - SQLTrace.ps1 version 1.0.0152.0 |
| 99 | + SQLTrace.ps1 version 1.0.0167.0 |
99 | 100 | by the Microsoft SQL Server Networking Team |
100 | 101 | " |
101 | 102 |
|
@@ -140,7 +141,7 @@ Usage: |
140 | 141 |
|
141 | 142 | .\SQLTrace.ps1 -Help |
142 | 143 | .\SQLTrace.ps1 -Setup [-INIFile SQLTrace.ini] |
143 | | - .\SQLTrace.ps1 -Start [-INIFile SQLTrace.ini] [-LogFolder folderpath] |
| 144 | + .\SQLTrace.ps1 -Start [-INIFile SQLTrace.ini] [-LogFolder folderpath] [-StopAfter minutes] |
144 | 145 | .\SQLTrace.ps1 -Stop [-INIFile SQLTrace.ini] |
145 | 146 | .\SQLTrace.ps1 -Cleanup [-INIFile SQLTrace.ini] |
146 | 147 | " |
@@ -418,6 +419,24 @@ Function StartTraces |
418 | 419 |
|
419 | 420 | LogInfo "Traces have started..." |
420 | 421 | Write-EventLog -LogName Application -Source $global:EventSourceName -EventID 3002 -Message "SQLTrace has started." |
| 422 | + |
| 423 | + # StopAfter logic |
| 424 | + |
| 425 | + if ($global:StopAfter -gt 0) |
| 426 | + { |
| 427 | + $global:StopAfterMinutes = $global:StopAfter |
| 428 | + while ($global:StopAfterMinutes -gt 0) |
| 429 | + { |
| 430 | + LogInfo "The trace will stop after $($global:StopAfterMinutes) minutes." |
| 431 | + Start-Sleep -Seconds 60 |
| 432 | + $global:StopAfterMinutes-- |
| 433 | + } |
| 434 | + StopTraces |
| 435 | + } |
| 436 | + else |
| 437 | + { |
| 438 | + LogInfo "The trace will run until manually terminated with: .\SqlTrace.ps1 -stop" |
| 439 | + } |
421 | 440 | } |
422 | 441 |
|
423 | 442 | Function FlushExistingTraces |
|
0 commit comments