views:

1889

answers:

3

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.

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?

A: 

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")  
}
Shay Levy
tried this method, throwing an error:Exception calling "Invoke" with "2" argument(s): "Exception has been thrown bythe target of an invocation."At D:\scripts\deployment\inc\deploy.ps1:124 char:28+ $pool.psbase.invoke( <<<< "recycle")
Recursieve
A: 

There is a similar question that might help shed light on how to recycle an app pool with PowerShell.

Scott Saad
A: 

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.

Recursieve