Menu
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.
Where do you turn when managing an IIS web server farm with potentially dozens or hundreds of app pools? PowerShell, of course.
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.
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.
To enable remoting, run Enable-PSRemoting on the target server. Ensure that firewall rules allow remote management to avoid connectivity issues.
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.
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
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
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 *
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.
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
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.
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.
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 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.