The following script will let you recycle an Application Pool on a remote server running IIS 6 or IIS 7 (with IIS 6 WMI Compatibility Features installed).

The script accepts 2 parameters: a server name and an application pools name, in the following format:

PS >.\RecycleIIsAppPool.ps1 server_name "application_pool_name"

To obtain a list of application pools on remote server, see: List IIS application pools on remote server using Powershell.

RecycleIIsAppPool.ps1:

$server          = $args[0]
$applicationPool = $args[1]

$appPool = Get-WmiObject -Authentication PacketPrivacy -Impersonation Impersonate
            -ComputerName $args[0] -namespace "root/MicrosoftIISv2"
            -class IIsApplicationPool |
Where-Object {$_.Name -eq "W3SVC/AppPools/$applicationPool" }

$appPool.Recycle()

Tags: , , ,

2 Responses


  1. Nehemoth on 31 Jan 2012

    I received the error :

    Missing expression after unary operator ‘-’.
    At C:\Users\Grimaldy Soto\Desktop\RecycleIIsAppPool.ps1:5 char:14
    + – <<<< ComputerName $args[0] -namespace "root/MicrosoftIISv2"
    + CategoryInfo : ParserError: (-:String) [], ParseException
    + FullyQualifiedErrorId : MissingExpressionAfterOperator

  2. LukeP on 01 Feb 2012

    Try removing line breaks in $appPool = Get-WmiObject command.


Leave your comment