You can use timeouts to protect the local computer and the remote computer from excessive resource use, both accidental and malicious. When timeouts are set on both the local and remote computer, Windows PowerShell uses the shortest timeout settings. The following timeouts are available in the basic configuration.
- The WSMan: drive provides several client-side
and service-side timeout settings, such as the MaxTimeoutMS
setting in the WSMan:\<ComputerName> node and the
MaxPacketRetrievalTimeSeconds settings in the
WSMan:\<ComputerName>\Service node. For more information
about the settings in the WSMan: drive, see WSMan Provider.
- You can protect the local computer by using
the CancelTimeout, IdleTimeout, OpenTimeout,
and OperationTimeout parameters of the New-PSSessionOption
cmdlet and the $PSSessionOption preference variable.
- You can also protect the remote computer by
setting timeout values programmatically in the session
configuration for the session.
When a timeout value does not permit a operation to complete, Windows PowerShell terminates the operation and generates an error. For example, Windows PowerShell generates the following error when the processing of a command exceeds the operation timeout that is set in the session.
ERROR: The WS-Management service cannot complete the operation within the time specified in OperationTimeout.
To change a timeout value
To resolve the error, change the command to complete within the timeout interval or determine the source of the timeout limit and increase the timeout interval to allow the command to complete.
For example, the following commands increase the OperationTimeout value. The first command uses the New-PSSessionOption cmdlet to create a session option object with an OperationTimeout value of 4 minutes (in MS). The second command uses the session option object to create a remote session with the extended OperationTimeout value.
C:\PS> $pso = new-pssessionoption -operationtimeout 240000 C:\PS> new-pssession -computername Server01 -sessionOption $pso
The following command sets the value of the $PSSessionOption preference variable to the session option with the four-minute OperationTimeout value. Thereafter, all PSSessions that you create during the current session have the extended operation timeout.
C:\PS> $PSSessionOption = new-pssessionoption -operationtimeout 240000
To use the new session option in all PSSessions that you create on the computer, add the $PSSessionOption preference variable to your Windows PowerShell profile. For more information about Windows PowerShell profiles, see about_Profiles.