I have a PowerShell script that is run automatically when our monitoring service detects that a website is down.
It is supposed to stop the AppPool (using Stop-WebAppPool -name $AppPool;
), wait until it is really stopped and then restart it.
Sometimes it the process does not actually stop, manifested by the error
Cannot Start Application Pool:
The service cannot accept control messages at this time.
(Exception from HRESULT: 0x80070425)"
when you try to start it again.
If it takes longer than a certain number of seconds to stop (I will chose that amount of time after I have timed several stops to see how long it usually takes), I want to just kill the process.
I know that I can get the list of processes used by workers in the AppPool by doing dir IIS:AppPoolsMyAppPoolWorkerProcesses
,
Process ID State Handles Start Time
---------- ----- ------- ----------
7124 Running
but I can't figure out how to actually capture the process id so I can kill it.
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…