
Data Structure
Networking
RDBMS
Operating System
Java
MS Excel
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
PHP
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
Use Timeout Parameter in Restart-Computer Cmdlet in PowerShell
As the name describes, with –Timeout parameter, you can restrict time for validations (PowerShell, WinRM, and WMI connectivity check after reboot) for –Wait and –For parameters and if the checks don’t complete during that time then it returns an error. This timeout value is in seconds. You can specify this parameter with either –Wait or –For parameter but with –For parameter you need to include –Wait parameter as well.
When -Timeout is specified with –Wait parameter, the overall checks (3 validations: PowerShell, WMI, and WINRM connectivity) then overall check time is restricted in seconds and when it is used with –For parameter then particular check time is considered.
In the below example, we are restarting Test1-Win2k12 remote server, and the timeout is 10 seconds. Server reboots and when the server comes up and if the checks don’t pass in 10 seconds then returns an error.
Restart-Computer Test1-Win2k12 -Wait -Timeout 10 -Force
Output (validation didn’t pass in 10 seconds) −
PS C:\Windows\system32> Restart-Computer Test1-Win2k12 -Wait -Timeout 10 Restart-Computer : Failed to restart the computer Test1- Win2k12 with the following error message: The computer did not finish restarting within the specified timeout period.. At line:1 char:1 + Restart-Computer Test1-Win2k12 -Wait -Timeout 10 + ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ \+ CategoryInfo : OperationTimeout: (Test1- Win2k12:String) [Restart-Computer], RestartComputerTimeoutException + FullyQualifiedErrorId : RestartComputerTimeout,Microsoft.PowerShe ll.Commands.RestartComputerCommand
You can also specify the -Timeout parameter with –Wait and –For both.
Restart-Computer Test1-Win2k12 -Wait -For PowerShell -Timeout 10 -Force