Which layer determines the effective idle timeout for PowerShell remoting sessions?
0 reputation · 02 Sept 2024, 04:09 UTC
0 reputation · 02 Sept 2024, 04:09 UTC
When deploying a low‑traffic administrative workload on a cloud VM, the goal is to keep the PowerShell remoting session alive only long enough to handle sporadic commands while minimizing host resource usage and associated costs.
Both the client and the server expose idle‑timeout settings: the client can pass New‑PSSessionOption -IdleTimeout and the server exposes IdleTimeoutMs in the WSMan session configuration. In Windows PowerShell 5.1 and PowerShell 7.x these settings coexist, yet the documented precedence is unclear, and the interaction may differ between HTTP and HTTPS transports.
Another concern is whether terminating a session due to an idle timeout releases the underlying host resources immediately, or if there is a lag caused by runspace garbage collection or the WinRM service’s internal cleanup.
33775 reputation · 02 Sept 2024, 05:47 UTC
1. Layer that enforces the timeout
IdleTimeoutMs value defined in the WinRM session configuration on the server is the authoritative timeout. The client’s New-PSSessionOption –IdleTimeout is advisory.2. Resource deallocation after termination
powershell.exe process list.3. Idle timeout alone is insufficient for cost reduction
Check the server‑side timeout:
Get-PSSessionConfiguration -Name MyConfig | Select-Object IdleTimeoutMsCreate a session with a longer client timeout and observe closure:
$opt = New-PSSessionOption -IdleTimeout 600000 # 10 min
$session = New-PSSession -ConfigurationName MyConfig -SessionOption $opt
# Wait and see when the session disappears
Get-PSSession | Format-Table Id, StateWatch the WinRM event log for Event 4001 to confirm the exact termination time.
After session closure, run Get-Process powershell -ErrorAction SilentlyContinue to ensure no lingering processes.
Monitor VM metrics (CPU, memory) to see that they drop after all sessions terminate.
If you’re using HTTPS, double‑check the transport configuration because SSL keep‑alive settings can override WinRM timeouts. Let us know the Transport value you’re using if the behavior differs from the steps above.
Use comments to ask for clarification. Post a solution as an answer.
No question comments on this page.