Thursday, January 10, 2013 2:24 PM
I have a restart section of IIS services in a script, but i noticed it wasn't always working, so i added some debug code and found out something interesting:
Restart-Service W3SVC,SMTPSVC,MSFtpsvc,WinRM,HTTPFilter -force 2>&1 | Tee-Object -File $env:temp\script_debug.log
When it's not working, this is the debug output:
Restart-Service : Time out has expired and the operation has not been completed
At C:\Test\testscript.ps1:59 char:20
+ Restart-Service <<<< W3SVC,SMTPSVC,MSFtpsvc,WinRM,HTTPFilter -force 2>&1 | Tee-Object -File $env:temp\dm-winlogs_debug.log
+ CategoryInfo : NotSpecified: (:) [Restart-Service], TimeoutException
+ FullyQualifiedErrorId : System.ServiceProcess.TimeoutException,Microsoft.PowerShell.Commands.RestartServiceCommand
I had previously read up on the "-force" parameter and thought this is just such a situation when force is useful:
Override restrictions that prevent the command from succeeding, apart
from security settings. e.g. -Force will stop and restart a
service that has dependent services.
Now a timeout prevented the command from succeeding, despite the use of "-force
Any ideas what i should to make this work no matter what?
Thursday, January 10, 2013 3:05 PM
Services that re very busy may take a long time to stop.
You are alos explicitly group even dependent services. Just restart the parent service. Restart only one service on each line. This will help avoid conflict.
- Marked As Answer by IamMredMicrosoft Employee, Owner Monday, January 21, 2013 7:29 AM