← All Scenarios
· Scenario 01
Basic Timeout via PSInvocationSettings
Goal
Verify that PSInvocationSettings.Timeout causes Invoke() to throw TimeoutException when the command runs too long.
Trying to break
Confirm the timeout actually fires and doesn't silently absorb the exception or leave the runspace in a wedged state.
3 test stepsPress Start to walk through the scenario step by step.
View full script source (basic-timeout.ps1)
# Scenario 01 — Basic Timeout via PSInvocationSettings
#
# GOAL: Verify that PSInvocationSettings.Timeout causes Invoke() to throw
# TimeoutException when the command runs too long.
$settings = [System.Management.Automation.PSInvocationSettings]::new()
$settings.Timeout = [TimeSpan]::FromSeconds(2)
$ps = [System.Management.Automation.PowerShell]::Create()
$ps.AddScript('Start-Sleep -Seconds 60') > $null
try {
$ps.Invoke($null, $settings) > $null
} catch [TimeoutException] {
Write-Host 'TimeoutException thrown'
}