SharePoint 2010 – Change Web Application to use Different Application Pool

When optimizing your farm, one of the recommendations from Microsoft is to only have 10 application pools running on the server (

Limit Maximum value Limit type Notes

Application pools

10 per web server


The maximum number is determined by hardware capabilities.

This limit is dependent largely upon:

  • The amount of memory allocated to the web servers

  • The workload that the farm is serving, that is, the user base and the usage characteristics (a single highly active application pool can utilize 10 GB or more)

But, once you’ve created your web applications, your ability to change the application pool the web application is running under is quite limited. Not something that can be done in the Central Admin GUI in any case so it either takes very careful planning or a way to go back and change the application pools.  Luckily, it can be quite easily achieved through a simple PowerShell script.

Here is a basic.ps1 file I created to easily change the Application Pool of a particular Web Application, as some point I may turn it into a real commandlet:

# Name:        Set-WebApplicataionPool.ps1 
# Description: Change which application pool the web application is using           
# Usage:       SetWebApplicationPool -WebAppURL "<ApplicationURL>" -ApplicationPoolName "<ApplicationPoolName>"
# By:
# Define 2 parameters for this script 

    [string] $WebAppURL = "$(Read-Host 'WebApplication URL')", 
    [string] $ApplicationPoolName = "$(Read-Host 'ApplicationPool Name')" 

Add-PSSnapin "Microsoft.SharePoint.PowerShell" -ErrorAction SilentlyContinue

if ($WebAppURL -eq "") 
   "Usage:    SetWebApplicationPool -WebAppURL <ApplicationURL> -ApplicationPoolName <ApplicationPoolName>"

Function Main()
    $apppool = [Microsoft.SharePoint.Administration.SPWebService]::ContentService.ApplicationPools | where {$_.Name -eq $ApplicationPoolName} 
    if ($apppool -eq $null){ 
        write-host -foreground red "The Application Pool $ApplicationPoolName does not exist!" 
    $webapp = get-spwebapplication -Identity $WebAppUrl 
    if ($webapp -eq $null){ 
        write-host -foreground red "The Web Application $WebAppUrl does not exist!" 
    $webapp.Applicationpool = $apppool 
    write-host -foreground green "$WebappURL Application Pool has been changed to $ApplicationPoolName" 


Pretty straight forward, only word of caution is of course don’t do this during production hours as the ProvisionGlobally() function will provision the Web application to all servers that are running the current object’s parent Web service.  In other words, there is a small service outage as among other things the web.config in the physical site directory will get rewritten which causes an application pool recycle (sort of self evident with this sort of change, but hey, at least you can’t say you weren’t warned).

EDIT: So, turns out if you reassign the web application to a generic application pool and delete the old application pools from the server, SharePoint is still expecting to see them and will throw a Health Analyzer alert if you delete them from the server since it is trying to check for them.  In order to remove unused application pools from the SharePoint configuration, please review: SharePoint 2010 – Application pools recycle when memory limits are exceeded (PART 2) where I show how to remove unused application pools from the ApplicationPools collection.

2 thoughts on “SharePoint 2010 – Change Web Application to use Different Application Pool”

Leave a Reply