I am writing a PowerShell script that stops an IIS Application Pool, does several other operations and then starts the AppPool again.
The problem is that the AppPool can take a long time to stop and if you try to start it before it is done stopping, you get the error
Start-WebAppPool : The service cannot accept control messages at this time. (Exception from HRESULT: 0x80070425)
Stop-WebAppPool -name $AppPool;
# do other stuff
Start-WebAppPool -name $AppPool;
What is the best way to get PowerShell to either
- keep trying to start the AppPool or
- force the AppPool to stop by killing the process.