Restart IIS6 application pool - ADSI error

2

Not sure what the eff' is wrong! I am using Powershell 2.0 on Windows 7. Had this same script working on Windows XP , am i just missing something?

$server = "server1-vm1.prod.ds.russell.com"
$name = "Superduper_Reports"
$iis = [ADSI]"IIS://$server/W3SVC/AppPools/$name"
$iis.psbase.invoke("recycle")

Error (that invoke looks okay to me?):

Exception calling "Invoke" with "2" argument(s): "Unknown error (0x80005000)"
At line:3 char:19
+ $iis.psbase.invoke <<<< ("recycle")
    + CategoryInfo          : NotSpecified: (:) [], MethodInvocationException
    + FullyQualifiedErrorId : DotNetMethodException

When just running $iis variable i get this error:

The following exception occurred while retrieving member "PSComputerName": "Unknown error (0x80005000)"
    + CategoryInfo          : NotSpecified: (:) [format-default], ExtendedTypeSystemException
    + FullyQualifiedErrorId : CatchFromBaseGetMember,Microsoft.PowerShell.Commands.FormatDefaultCommand

Roooarr! I'd rather use ADSI over WMI! Any help? :)

powershell
powershell-2.0
asked on Stack Overflow Jul 14, 2010 by xbnevan • edited Feb 23, 2013 by koopajah

2 Answers

1

I think that you can use WebAdministration module for that

Import-Module WebAdministration
Get-Command -Module WebAdministration
Get-ChildItem IIS:

You will find a lots of Cmdlets to admin IIS and a new drive IIS:

You will find on this Microsoft Web site some explanations.

answered on Stack Overflow Mar 23, 2011 by JPBlanc • edited Mar 27, 2014 by JPBlanc
0

This question has a WMI script which has been stated to work.

Alternatively ADSI equivalent would look something like this ...

http://geekswithblogs.net/Lance/archive/2010/12/16/powershell-ndash-recycle-all-iis-app-pools.aspx

function Recycle-AppPools {

    param(
    [string] $server = "3bhs001",
    [int] $mode = 1, # ManagedPipelineModes: 0 = integrated, 1 = classic
    ) 

    $iis = [adsi]"IIS://$server/W3SVC/AppPools"
    $iis.psbase.children | %{ 
        $pool = [adsi]($_.psbase.path); 
        if ($pool.AppPoolState -eq 2 -and $pool.ManagedPipelineMode -eq $mode) {
           # AppPoolStates:  1 = starting, 2 = started, 3 = stopping, 4 = stopped          
           $pool.psbase.invoke("recycle") 
        }
   }

}

You can't recycle a stopped AppPool however so you need to check for that.

answered on Stack Overflow Mar 23, 2011 by JTew • edited May 23, 2017 by Community

User contributions licensed under CC BY-SA 3.0