简体   繁体   English

使用PowerShell回收IIS应用程序池:“异常调用回收”

[英]Recycling IIS application pool using PowerShell: “Exception calling Recycle”

It looks like a recent windows update has broken some functionality I was using to recycle IIS6 application pools, as this has been working for months up to today. 看起来最近的Windows更新破坏了我用来回收IIS6应用程序池的一些功能,因为这已经工作了几个月到今天。

Exception calling "Recycle" : "Win32: The object identifier does not representException calling "Recycle" : "Win32: The object identifier does not represent a valid object.

the function I was using to recycle the application pools was: 我用来回收应用程序池的功能是:

function recycle-pool($strServerName)
{
    $objWMI = [WmiSearcher] "Select * From IIsApplicationPool"
    $objWMI.Scope.Path = "\\" + $strServerName + "\root\microsoftiisv2"
    $objWMI.Scope.Options.Authentication = 6
    $pools = $objWMI.Get()
    foreach ($pool in $pools)
    {
        $pool.recycle()
        if (!$?)
        {
            Write-Host $pool.name " - ERROR"
        }
        else
        {
            Write-Host $pool.name " - Recycled"
        }
}

Any idea on what the problem is and how I should approach this? 对问题是什么以及如何处理这个问题有任何想法?

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: 最初的问题是针对IIS6,但我在Windows 2012上使用WebAdministration模块的Restart-WebAppPool遇到了类似的问题。所以我退回到调用AppCMD,这很好:

& $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: 您可以尝试使用ADSI进行回收:

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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM