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?

Grace Note
  • 3,205
  • 4
  • 35
  • 55
Karl Glennon
  • 3,149
  • 4
  • 29
  • 31
  • it looks like the $pool object may be null, so it must be an issue with how I am selecting the application pool objects – Karl Glennon Feb 26 '09 at 12:59

3 Answers3

3

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.

Bewc
  • 431
  • 5
  • 15
2

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.

Karl Glennon
  • 3,149
  • 4
  • 29
  • 31
1

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
  • 121,444
  • 32
  • 184
  • 206
  • tried this method, throwing an error: Exception calling "Invoke" with "2" argument(s): "Exception has been thrown by the target of an invocation." At D:\scripts\deployment\inc\deploy.ps1:124 char:28 + $pool.psbase.invoke( <<<< "recycle") – Karl Glennon Feb 26 '09 at 14:18