BDC Hamburger Icon

Menu

Close
BDC Logo
Search Icon
Advertising Disclosure
Close
Advertising Disclosure

Business.com 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.

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.

Mark Fairlie
Written by: Mark Fairlie, Senior AnalystUpdated Dec 05, 2024
Gretchen Grunburg,Senior Editor
Business.com earns commissions from some listed providers. Editorial Guidelines.
Table Of Contents Icon

Table of Contents

Open row

Microsoft PowerShell is a trusted tool for many information technology (IT) professionals managing Internet Information Services (IIS) web server farms with dozens or even hundreds of app pools. With the WebAdministration PowerShell module — included as part of the IIS package — and PowerShell’s robust remote management capabilities, you can efficiently create, modify and remove app pools. We’ll explain how to leverage these tools to streamline your app pool management tasks.

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 parameter on most of the cmdlets. Unfortunately, this option doesn’t exist for IIS cmdlets. 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 frustrating the first time you try this because you won’t see that familiar –ComputerName parameter on many of the cmdlets.

William Mabotja, Azure-certified senior software developer at Atlas Finance, recommends running Get-Module -ListAvailable IIS before doing anything else. “When you run this command, you’re executing a critical diagnostic step that reveals all the IIS-related modules available on your system,” Mabotja explained. “This can come in very handy.”

Here’s how to manage IIS application pools with PowerShell. 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. Prepare for remoting.

To enable remoting, run Enable-PSRemoting on the target server. Ensure that firewall rules allow remote management to avoid connectivity issues.

2. Import the WebAdministration module. 

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

Import-Module WebAdministration

The WebAdministration module imports all IIS-related cmdlets and creates the IIS drive, where most (or all) app pool configuration happens. This setup simplifies managing application pools, much like syncing folders with PowerShell organizes files efficiently.

Did You Know?Did you know
The WebAdministration module comes preinstalled with IIS on specific versions of Windows Server, such as Windows Server 2016 and later. If it's missing, you may need to add the IIS Management Scripts and Tools feature via Server Manager or PowerShell.

3. See if app pools already exist.

Mabotja emphasized the importance of verifying existing app pools. “Always verify your existing app pools before adding new ones,” Mabotja advised. “This helps prevent redundancy and keeps your IIS environment well organized.”

Run the following command to see if any app pools already exist:

Get-ChildItem –Path IIS:\AppPools

IIS application pools

In this example, an app pool named GHI already exists, so creating another one makes sense to support additional applications or configurations.

4. Make a new app pool. 

The IIS drive makes creating a new app pool easy — similar to managing file system access control lists with PowerShell. You’ll use New-Item and specify the path:

New-Item –Path IIS:\AppPools\MyAppPool

IIS application pools image example

We’ve now created a new app pool called MyAppPool

5. Check properties. 

Next, check all the properties on that app pool using Get-ItemProperty. Combine it with Select-Object to view all the properties it returns. This will display all property names and values, helping you identify which ones need modification with Set-ItemProperty. With this approach, you can customize each app pool to meet your exact specifications.

Get-ItemProperty IIS:\AppPools\MyAppPool | Select-Object *

IIS application example

6. Modify a property. 

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

Set-ItemProperty -Path IIS:\AppPools\MyAppPool -Name managedRuntimeVersion -Value ‘v4.0’

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

Some other common properties to adjust include autoStart and managedPipelineMode, which allow more control over when and how the app pool functions.

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

7. Remove the app pool.

Once you’re finished with the app pool, you can remove it using the built-in PowerShell cmdlet Remove-WebAppPool. Simply specify the app pool’s name and it will be deleted:

Remove-WebAppPool -Name MyAppPool

8. Run code remotely. 

So far, we’ve been executing code locally. However, what if you need your code to run on a remote IIS server? Using loops and PowerShell remoting allows you to achieve this. 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

This script creates a new app pool, sets a property and then removes it. This process highlights how PowerShell functions can streamline multiple tasks into a single script, making management more efficient.

We also utilized the $using variable, which is essential when executing code on a remote computer. PowerShell expands this variable to reference the actual value of $appPoolName that was declared locally on your client computer.

TipBottom line
Remoting is a robust PowerShell feature for managing offsite IIS servers. Ensure you have proper permissions and secure credentials to align with cybersecurity and risk management best practices.

Managing IIS in hybrid environments

Now that we’ve covered IIS app pool management, let’s explore how this applies in hybrid environments, where on-premises servers coexist with cloud platforms like Azure.

Mabotja explained that PowerShell is an effective command center for IIS management when dealing with on-premises environments, but hybrid environments can get tricky. “When you’re juggling dozens or hundreds of app pools across server farms, manual clicking becomes impractical,” Mabotja cautioned. “But today’s reality is that many organizations are running hybrid environments, with some applications on-premises and others in Azure. That’s where things get interesting.”

In hybrid environments, IIS administration often goes beyond managing on-premises servers. Many organizations now leverage Azure App Services for hosting applications in the cloud, requiring administrators to adapt their PowerShell skills to include Azure environments.

Getting started with Azure PowerShell

Azure PowerShell provides tools for managing web apps in Azure App Services. “In Azure environments, we’ve got additional superpowers,” Mabotja noted. Use the following commands to get started:

# Azure PowerShell approach

Install-Module -Name Az

Connect-AzAccount

Get-AzWebApp | Select-Object Name, ResourceGroup, State

“Managing application availability in Azure App Services is crucial for maintaining optimal performance and user experience,” Mabotja advised. “PowerShell provides a streamlined way to automate this process, allowing you to quickly identify and restart any stopped web apps in your Azure environment.”

For example, this script checks the status of your Azure App Services and restarts any that are stopped:

# Azure App Service management

Get-AzWebApp |

Where-Object { $_.State -eq ‘Stopped’ } |

ForEach-Object { 

     Start-AzWebApp -ResourceGroupName $_.ResourceGroup -Name $_.Name 

}

This automation ensures application health with minimal manual intervention, freeing up tech teams to focus on more critical tasks while maintaining high availability.

PowerShell is a Swiss Army knife for IIS management

PowerShell is a robust IIS application pool management tool. As Mabotja describes it, “PowerShell isn’t just another tool in your belt; it’s your Swiss Army knife for IIS management.” 

When handling large-scale server farms, automation becomes essential. “When you’re dealing with dozens or hundreds of application pools across server farms, you can’t possibly click through IIS Manager all day,” Mabotja explained. “That’s like trying to mow a football field with scissors! PowerShell automation is what separates the pros from the amateurs.”

For beginners, Mabotja recommends starting with the basics to build confidence. “The WebAdministration module is like your trusty old Volkswagen — it’s been around forever and still gets the job done,” Mabotja noted. “But the IISAdministration module? That’s your Tesla — newer, more powerful, but you need to know how to drive it.”

In other words, if you’re new to IIS management, begin with the well-established WebAdministration module. Once you’ve mastered it, you can transition to the more advanced IISAdministration module to take advantage of its enhanced capabilities.

Mabotja emphasized that the core principles apply across different environments. “Whether you’re managing traditional IIS or Azure App Services, the principles remain the same,” Mabotja explained. “Automate everything, test thoroughly and always have a backup plan.”

Adam Bertram contributed to this article. 

Did you find this content helpful?
Verified CheckThank you for your feedback!
Mark Fairlie
Written by: Mark Fairlie, Senior Analyst
Mark Fairlie brings decades of expertise in telecommunications and telemarketing to the forefront as the former business owner of a direct marketing company. Also well-versed in a variety of other B2B topics, such as taxation, investments and cybersecurity, he now advises fellow entrepreneurs on the best business practices. At business.com, Fairlie covers a range of technology solutions, including CRM software, email and text message marketing services, fleet management services, call center software and more. With a background in advertising and sales, Fairlie made his mark as the former co-owner of Meridian Delta, which saw a successful transition of ownership in 2015. Through this journey, Fairlie gained invaluable hands-on experience in everything from founding a business to expanding and selling it. Since then, Fairlie has embarked on new ventures, launching a second marketing company and establishing a thriving sole proprietorship.
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