| 1 | param ( |
| 2 | [int] $PeriodSeconds = 3600, |
| 3 | [ValidateNotNullOrEmpty()] |
| 4 | [string] $Profile = (Join-Path $PSScriptRoot "wsl.wprp") |
| 5 | ) |
| 6 | |
| 7 | Set-StrictMode -Version Latest |
| 8 | $ErrorActionPreference = "Stop" |
| 9 | |
| 10 | trap |
| 11 | { |
| 12 | try { & wpr.exe -cancel | Out-Null } catch {} |
| 13 | throw |
| 14 | } |
| 15 | |
| 16 | [console]::TreatControlCAsInput = $true |
| 17 | |
| 18 | |
| 19 | Write-Host "Press any key to exit" |
| 20 | |
| 21 | $running = $true |
| 22 | while($running) |
| 23 | { |
| 24 | & wpr.exe -start $Profile -filemode |
| 25 | $rotation = (Get-Date).AddSeconds($PeriodSeconds) |
| 26 | |
| 27 | while($rotation -Gt (Get-Date)) |
| 28 | { |
| 29 | if ($Host.UI.RawUI.KeyAvailable) |
| 30 | { |
| 31 | $keyPressed = $Host.UI.RawUI.ReadKey("NoEcho, IncludeKeyUp, IncludeKeyDown") |
| 32 | if ($keyPressed.KeyDown -eq "True") |
| 33 | { |
| 34 | $running = $false |
| 35 | Write-Host "Exiting" |
| 36 | break |
| 37 | } |
| 38 | } |
| 39 | |
| 40 | [Threading.Thread]::Sleep(1000) |
| 41 | } |
| 42 | |
| 43 | $file = Get-Date ($rotation.ToUniversalTime()) -UFormat '%Y-%m-%d %H-%M-%S' |
| 44 | $file += ".etl" |
| 45 | Write-Host Writing logs to $file |
| 46 | & wpr.exe -stop $file |
| 47 | } |