receives compensation from some of the companies listed on this page. Advertising Disclosure

How to Manage IIS Application Pools With PowerShell

Updated Jul 06, 2023

Table of Contents

Open row

Microsoft PowerShell is the favored tool of many information technology (IT) experts who manage Internet Information Services (IIS) web server farms with dozens or hundreds of app pools.

You can create, modify and remove app pools using the WebAdministration PowerShell module that comes as part of the IIS package and the tool’s remote management capabilities.

TipBottom line

Save time and reduce errors by using PowerShell to automate IIS web server management.

How to manage IIS application pools with PowerShell

If you’ve never used PowerShell to manage your IIS servers, your first inclination might be to look for a –ComputerName on most of the cmdlets. Unfortunately, this is not the case. To manage IIS servers remotely, you must use PowerShell remoting with the Invoke-Command cmdlet. 

Although not a deal-breaker, using the Invoke-Command cmdlet makes the code a little more verbose. It can be pretty frustrating the first time you try this because you won’t see that familiar –ComputerName parameter on many of the cmdlets.

Note: Going forward, we’ll build code to input into a scriptblock. We’ll then use Invoke-Command to execute this scriptblock on the remote IIS server.

1. Import the WebAdministration module. 

To manage application pools, we must first import the WebAdministration module.

Import-Module WebAdministration

The WebAdministration module imports all ISS cmdlets and creates the IIS drive. That’s where most (or all) of the app pool configuration happens. It’s similar to how syncing folders with PowerShell organizes your files in a streamlined way.

Did You Know?Did you know

The WebAdministration module comes preinstalled with the IIS with certain versions of Windows Server.

2. See if app pools already exist.

Now, we’ll check to see if any app pools already exist:

Get-ChildItem –Path IIS:AppPools

IIS application pools

It looks like we have one called GHI already, so making another one makes sense. 

3. Make a new app pool. 

The IIS drive makes creating a new app pool easy. It’s like manipulating file system ACLs using PowerShell. To do both, you use New-Item and specify the path:

New-Item –Path IIS:AppPoolsMyAppPool

IIS application pools image example

We’ve now created a new app pool. 

4. Check properties. 

Next, we’ll check all the properties on that app pool using Get-ItemProperty and select all the properties it returns with Select-Object. This will return all property names and values to help us determine which ones we must modify with Set-ItemProperty. With this command, we can make each app pool to our exact specifications.

Get-ItemProperty IIS:AppPoolsMyAppPool | select *

IIS application example

5. Modify a property. 

Now that we have an app pool and can see its properties, let’s modify a property. Maybe you want to use a specific .NET runtime version with the app pool. Again, using the IIS drive, you can use Set-ItemProperty to manage app pools as you would with the file system, registry, certificates and other items with a PowerShell drive:

Set-ItemProperty -Path IIS:AppPoolsMyAppPool -Name managedRuntimeVersion -Value ‘v4.0’

By using Set-ItemProperty, we can modify nearly all app pool properties.

FYIDid you know

Managing and modifying app pools with PowerShell is straightforward and allows for maximum customization.

6. Remove the app pool.

Now that we’re done with the app pool, we must remove it. We have a built-in PowerShell cmdlet called Remove-WebAppPool. Specify the name and it’s gone. 

Remove-WebAppPool -Name MyAppPool

7. Run code remotely. 

We’ve been executing code locally up until now. However, what if we need our code to run on a remote IIS server? Remoting with loops helps us do this. We must bundle the code in a scriptblock and use Invoke-Command to execute it on the remote server: 

$appPoolName = ‘MyAppPool’
$scriptBlock = {
    Import-Module WebAdministration
    New-Item –Path IIS:AppPools$using:appPoolName
    Set-ItemProperty -Path
    IIS:AppPools$using:appPoolName -Name
    managedRuntimeVersion -Value ‘v4.0’
    Remove-WebAppPool -Name $using:appPoolName
Invoke-Command –ComputerName SOMEIISSERVER –ScriptBlock $scriptBlock

TipBottom line

Remoting is a robust PowerShell feature that allows you to manage IIS servers that aren’t on your local machine.

Making and managing app pools with PowerShell

This code would create a new app pool named MyAppPool, set a property, then remove it. This is a great example of how functions in PowerShell allow you to perform multiple tasks with one set of commands.

You’ll notice we’re using the $using variable. Since the code in the script block will execute on a remote computer, this is necessary for PowerShell to expand that variable and use the actual value of $appPoolName that was declared locally on your client computer.

Mark Fairlie contributed to this article.

Adam Bertram
Contributing Writer at
Adam Bertram is a 20-year veteran of IT and experienced online business professional. He's an entrepreneur, IT influencer, Microsoft MVP, blogger, trainer and content marketing writer for multiple technology companies. Adam is also the founder of the popular IT career development platform TechSnips. Catch up on Adam's articles at, connect on LinkedIn, or follow him on Twitter at @adbertram or the TechSnips Twitter account at @techsnips_io.
BDC Logo

Get Weekly 5-Minute Business Advice

B. newsletter is your digest of bite-sized news, thought & brand leadership, and entertainment. All in one email.

Back to top