Quantcast
Channel: Windows PowerShell forum
Viewing all articles
Browse latest Browse all 21975

Retry command until it is successful

$
0
0

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

  1. keep trying to start the AppPool or
  2. force the AppPool to stop by killing the process.


Viewing all articles
Browse latest Browse all 21975

Trending Articles