Recycle IIS Application Pool Using PowerShell: "Calling a Call for Exception"

It seems that a recent Windows update violated some of the features that I used to recycle IIS6 application pools, as it worked for several months now.

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

The function that I used to recycle 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 what the problem is and how should I approach this?

+3
source share
3 answers

One of the application pools was stopped, which caused an error. Other application pools were disposed of fine. The above code is suitable for everyone else.

+2

IIS6, - WebAdministration Restart-WebAppPool Windows 2012. AppCMD, :

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

. , .

+3

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")  
}
+1
source

Source: https://habr.com/ru/post/1703885/


All Articles