← All Scenarios
· Scenario 08
Nested PowerShell Timeout
Goal
Verify timeout behaves correctly when PowerShell instances are nested — outer instance calls inner instance which hangs. No deadlock between outer stop and inner pipeline.
Trying to break
Timeout on outer invocation should stop nested invocations gracefully. Runspace state should be clean after timeout. A fresh runspace should be usable immediately after.
2 test stepsPress Start to walk through the scenario step by step.
View full script source (nested-timeout.ps1)
$ps = [PowerShell]::Create()
$ps.Runspace = $rs
$ps.AddScript('Start-Sleep -Seconds 60') > $null
$settings = [PSInvocationSettings]::new()
$settings.Timeout = [TimeSpan]::FromSeconds(3)
try {
$ps.Invoke($null, $settings) > $null
} catch [TimeoutException] {
Write-Host 'PASS: TimeoutException from nested scenario'
}