Recycling IIS application pool using PowerShell: "Exception calling Recycle" Recycling IIS application pool using PowerShell: "Exception calling Recycle" powershell powershell

Recycling IIS application pool using PowerShell: "Exception calling Recycle"


The original question was for IIS6, but I ran into something similar using the WebAdministration Module's Restart-WebAppPool on Windows 2012. So I dropped back to calling AppCMD, and that worked fine:

& $env:windir\system32\inetsrv\appcmd recycle apppool "YOURAPPPOOLNAMEHERE"

Sometimes, you don't have to over-engineer the solution. Hope that helps others some day.


One of the application pools was stopped, which was causing the error. The other application pools were recycling fine. The code above is ok to use for anyone else.


You can try to recycle with ADSI:

$server = "IIsServerName"  $iis = [adsi]"IIS://$server/W3SVC/AppPools"  $iis.psbase.children | foreach {      $pool = [adsi]($_.psbase.path)       $pool.psbase.invoke("recycle")  }