I've set the OperationTimeout to 10 seconds, but when I run a command that sleeps for 20 seconds inside an Invoke-Command block on a remote computer, I don't get an error. Here's the code:
$sessionOptions = New-PSSessionOption -OperationTimeout 10000
$session = New-PSSession -ComputerName "RemoteComputerName" -SessionOption $sessionOptions
try {
Invoke-Command -Session $session -ScriptBlock {
Start-Sleep -Seconds 20
Get-Date
}
} catch {
Write-Error "OperationTimeoutException occurred: $_"
}
Remove-PSSession -Session $session
Could someone explain why there's no OperationTimeoutException error occurring in this scenario?
OperationTimeoutdoes not impose a time limit on commands or processes running in a remote session and does not affect other remoting protocols like SSH$remoteJob = Invoke-Command ... -AsJob, then useWait-Job -Timeout 10to impose the timeout