Monitor and restart IIS pool after failure.

Hi Guys

 

We are trying to perform monitoring via PowerShell monitor, specifically monitoring an IIS pool on our Windows machines.

 

We were able to perform the monitoring, which returned a 200 error (via a link health check). However, we would like WUG to automatically restart this pool whenever it receives any error other than a 200 error.

 

Is this possible? If so, could you help us with our code? We tried several ways, but the IIS pool wasn't restarted.

 

Here's the code we're using:

 

http://" + $Context.GetProperty("Address") + "/apolo/services/sales/hc"

 

$AppPoolName = "apolosales"

 

$Headers = @{

"Content-Type" = "application/json"

 

}

 

$Response = Invoke-RestMethod -Uri $URL -Method Post -Headers $Headers

 

if ($Response = "False"){

 

$Context.SetResult(0, $Response)

 

}

 

else {

 

& "$env:SystemRoot\System32\inetsrv\appcmd.exe" start apppool "$AppPoolName"

 

$Context.SetResult(1, $Response)

 

}

 

Regards,