@@ -71,6 +71,29 @@ function Get-StartupPhaseWindows {
7171 return $windows
7272}
7373
74+ function Get-StartupArmValidity {
75+ param ($Arm )
76+ if ($null -eq $Arm -or $Arm.status -ne ' captured' -or $null -eq $Arm.trace ) {
77+ return [pscustomobject ]@ {
78+ Status = if ($Arm ) { [string ]$Arm.status } else { ' missing' }
79+ BlockedChild = 0
80+ BlockedNetwork = 0
81+ RejectionReason = $null
82+ }
83+ }
84+ $blockedChild = if ($null -ne $Arm.trace.blocked ) { [int ]$Arm.trace.blocked.child } else { 0 }
85+ $blockedNetwork = if ($null -ne $Arm.trace.blocked ) { [int ]$Arm.trace.blocked.network } else { 0 }
86+ $reasons = @ ()
87+ if ($blockedChild -gt 0 ) { $reasons += ' blocked-child-process' }
88+ if ($blockedNetwork -gt 0 ) { $reasons += ' blocked-network' }
89+ [pscustomobject ]@ {
90+ Status = if ($reasons.Count -gt 0 ) { ' rejected' } else { ' captured' }
91+ BlockedChild = $blockedChild
92+ BlockedNetwork = $blockedNetwork
93+ RejectionReason = $reasons -join ' ,'
94+ }
95+ }
96+
7497function ConvertTo-UtcFileTime {
7598 # ConvertFrom-Json in PowerShell 7 may already have turned ISO strings into DateTime values.
7699 param ($Value )
@@ -122,26 +145,42 @@ function Get-NativeSetupMilestones {
122145 AI-setup page) is observed in the UI and supplied separately; see Resolve-NativeSetupOutcome.
123146 Only fixed message prefixes are read; message bodies are not returned.
124147 #>
125- param ([string []]$Lines )
148+ param (
149+ [string []]$Lines ,
150+ [Int64 ]$AttemptStartTicks = 0 ,
151+ [Int64 ]$EndTicks = [Int64 ]::MaxValue
152+ )
126153 $records = @ (foreach ($line in $Lines ) {
127154 if ([string ]::IsNullOrWhiteSpace($line )) { continue }
128- try { $entry = $line | ConvertFrom-Json - DateKind String } catch { continue }
155+ try { $entry = $line | ConvertFrom-Json } catch { continue }
129156 if ($null -eq $entry.PSObject.Properties [' ts' ] -or $null -eq $entry.PSObject.Properties [' msg' ]) { continue }
157+ $ticks = [Int64 ](ConvertTo-UtcFileTime $entry.ts )
158+ if ($ticks -gt $EndTicks ) { continue }
130159 [pscustomobject ]@ {
131- Ticks = [ Int64 ]( ConvertTo-UtcFileTime $entry .ts )
160+ Ticks = $ticks
132161 Level = if ($entry.PSObject.Properties [' level' ]) { [string ]$entry.level } else { ' ' }
133162 Message = [string ]$entry.msg
134163 Step = if ($entry.PSObject.Properties [' data' ] -and $entry.data -and $entry.data.PSObject.Properties [' step' ]) { [string ]$entry.data.step } else { $null }
135164 }
136165 })
137166 $startIndex = -1
138167 for ($i = 0 ; $i -lt $records.Count ; $i ++ ) {
139- if ($records [$i ].Message -eq ' Native Gateway setup attempt started.' ) { $startIndex = $i }
168+ if ($records [$i ].Message -eq ' Native Gateway setup attempt started.' -and
169+ ($AttemptStartTicks -eq 0 -or $records [$i ].Ticks -eq $AttemptStartTicks )) {
170+ $startIndex = $i
171+ }
140172 }
141173 if ($startIndex -lt 0 ) {
142174 return [pscustomobject ]@ { Outcome = ' not-started' ; FailedStep = $null ; Milestones = @ () }
143175 }
144- $attempt = @ ($records | Select-Object - Skip $startIndex )
176+ $nextStart = $records.Count
177+ for ($i = $startIndex + 1 ; $i -lt $records.Count ; $i ++ ) {
178+ if ($records [$i ].Message -eq ' Native Gateway setup attempt started.' ) {
179+ $nextStart = $i
180+ break
181+ }
182+ }
183+ $attempt = @ ($records [$startIndex .. ($nextStart - 1 )])
145184 $milestones = [Collections.Generic.List [object ]]::new()
146185 $milestones.Add ([pscustomobject ]@ { Name = ' attempt-started' ; Ticks = $attempt [0 ].Ticks })
147186 $seen = @ {}
@@ -303,14 +342,6 @@ function Wait-ForFile {
303342 return $null
304343}
305344
306- function Test-InstanceRecording {
307- # wpr requires -instancename to be the last argument.
308- param ([string ]$Name )
309- $wpr = Join-Path $env: SystemRoot ' System32\wpr.exe'
310- $output = & $wpr - status - instancename $Name 2>&1 | Out-String
311- return ($output -notmatch ' not recording' )
312- }
313-
314345function Start-GatewayTraceRecorder {
315346 <#
316347 Launches the elevated recorder through UAC and waits for it to report a started instance.
@@ -339,13 +370,32 @@ function Stop-GatewayTraceRecorder {
339370 param ([string ]$InstanceName , $Paths , [int ]$StopTimeoutSeconds )
340371 [IO.File ]::WriteAllText($Paths.Stop , ' stop' )
341372 $signal = Wait-ForFile - Paths @ ($Paths.Status ) - TimeoutSeconds $StopTimeoutSeconds
342- if ($null -ne $signal ) {
373+ if ($null -eq $signal ) {
374+ Write-Warning " Recorder status was not received for WPR instance $InstanceName ."
375+ return [pscustomobject ]@ { outcome = ' missing-status' ; cancel = ' unknown' ; instance_recording_after = $null }
376+ }
377+ try {
343378 $status = Get-Content - LiteralPath $Paths.Status - Raw | ConvertFrom-Json
344- Write-Host " Recorder outcome: $ ( $status.outcome ) ; cancel: $ ( $status.cancel ) "
379+ } catch {
380+ Write-Warning " Recorder status could not be read for WPR instance $InstanceName ."
381+ return [pscustomobject ]@ { outcome = ' invalid-status' ; cancel = ' unknown' ; instance_recording_after = $null }
382+ }
383+ if ($status.instance -ne $InstanceName -or [string ]::IsNullOrWhiteSpace([string ]$status.outcome )) {
384+ Write-Warning " Recorder status did not match WPR instance $InstanceName ."
385+ return [pscustomobject ]@ { outcome = ' invalid-status' ; cancel = ' unknown' ; instance_recording_after = $null }
345386 }
346- if ($null -eq $signal -or (Test-InstanceRecording $InstanceName )) {
387+ Write-Host " Recorder outcome: $ ( $status.outcome ) ; cancel: $ ( $status.cancel ) "
388+ if ($status.instance_recording_after -eq $true ) {
347389 Write-Warning " WPR instance $InstanceName may still be recording. Run elevated: wpr.exe -cancel -instancename $InstanceName "
390+ return [pscustomobject ]@ {
391+ instance = $InstanceName
392+ outcome = ' recording-still-active'
393+ recorder_outcome = $status.outcome
394+ cancel = $status.cancel
395+ instance_recording_after = $true
396+ }
348397 }
398+ return $status
349399}
350400
351- Export-ModuleMember - Function Get-IntervalUnionLength , Get-ClippedIntervals , Get-PayloadPackageGroup , Get-StartupPhaseWindows , ConvertTo-UtcFileTime , Get-CompleteMpPerformanceReport , Get-NativeSetupMilestones , Get-NativeSetupWindows , Resolve-NativeSetupOutcome , Read-SetupStopSignal , Get-NativeSetupUiStateFromIds , Get-NativeSetupUiState , Test-IsElevated , New-PrivateDirectory , Wait-ForFile , Test-InstanceRecording , Start-GatewayTraceRecorder , Stop-GatewayTraceRecorder
401+ Export-ModuleMember - Function Get-IntervalUnionLength , Get-ClippedIntervals , Get-PayloadPackageGroup , Get-StartupPhaseWindows , Get-StartupArmValidity , ConvertTo-UtcFileTime , Get-CompleteMpPerformanceReport , Get-NativeSetupMilestones , Get-NativeSetupWindows , Resolve-NativeSetupOutcome , Read-SetupStopSignal , Get-NativeSetupUiStateFromIds , Get-NativeSetupUiState , Test-IsElevated , New-PrivateDirectory , Wait-ForFile , Start-GatewayTraceRecorder , Stop-GatewayTraceRecorder
0 commit comments