is supported by commissions from providers listed on our site. Read our Editorial Guidelines.
BDC Hamburger Icon


BDC Logo
Search Icon
Advertising Disclosure
Advertising Disclosure aims to help business owners make informed decisions to support and grow their companies. We research and recommend products and services suitable for various business types, investing thousands of hours each year in this process.

As a business, we need to generate revenue to sustain our content. We have financial relationships with some companies we cover, earning commissions when readers purchase from our partners or share information about their needs. These relationships do not dictate our advice and recommendations. Our editorial team independently evaluates and recommends products and services based on their research and expertise. Learn more about our process and partners here.

Updated Jul 06, 2023

How to Manage IIS Application Pools With PowerShell

Where do you turn when managing an IIS web server farm with potentially dozens or hundreds of app pools? PowerShell, of course.

author image
Written By: Adam BertramSenior Writer & Expert on Business Operations
Verified CheckEditor Verified
Verified Check
Editor Verified
A editor verified this analysis to ensure it meets our standards for accuracy, expertise and integrity.

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.

author image
Written By: Adam BertramSenior Writer & Expert on Business Operations
Adam Bertram is an IT expert and business owner who has spent decades advising on network administration and security, designing and building infrastructure, and creating and teaching courses on Windows Server, Powershell and more. While maintaining his own IT business, he has provided hands-on DevsOps services for clients like JPMorgan Chase. Bertram, who has a degree in computer science, holds Microsoft, Cisco and CompTIA credentials. He has written numerous tutorials, guides and books, including "Building Better PowerShell Code: Applying Proven Practices One Tip at a Time."
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