Tag Archives: Application Pools

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 (http://technet.microsoft.com/en-us/library/cc262787(v=office.14).aspx).

Limit Maximum value Limit type Notes

Application pools

10 per web server

Supported

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:          ieDaddy.com
#--------------------------------------------------------------------------------------- 
# Define 2 parameters for this script 


param(
    [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>"
   exit; 
} 

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!" 
        return; 
    } 
    $webapp = get-spwebapplication -Identity $WebAppUrl 
    if ($webapp -eq $null){ 
        write-host -foreground red "The Web Application $WebAppUrl does not exist!" 
        return; 
    } 
    $webapp.Applicationpool = $apppool 
    $webApp.Update() 
    $webApp.ProvisionGlobally() 
    write-host -foreground green "$WebappURL Application Pool has been changed to $ApplicationPoolName" 
    return;
} 

Main

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.

SharePoint 2010 – Application pools recycle when memory limits are exceeded.

Title Application pools recycle when memory limits are exceeded.
Severity 0 – Rule Execution Failure
Category Performance
Explanation Access is denied.
Remedy In the Internet Information Services Manager, uncheck any memory-based maximums set for the application pools named above. For more information about this rule, see "http://go.microsoft.com/fwlink/?LinkID=142692".
Failing Services SPWebService (WSS_Administration)

Another fun MSCryptic message from our good friend the SharePoint Health Analyzer.  In this case, Microsoft has yet to allow us to separate out the HA rules to individual servers Unfortunately these rules tend to be an all or nothing approach, and in the case of this rule’s scope we get two choices:

image

So, what this means is that if we’re running a medium or large farm and we’ve gone and separated out our various application pools so that the Central Admin (CA) and the Web Front End (WFE) are on different services and are in fact isolated, then even though everything is properly set up, because it does not see certain app pools on a server that it thinks should be there it flags the SPHA rule.

Hopefully MS will someday allow us to configure the rules to run on a per-server level instead of just farm level.  In the meantime, three possible solutions:

  1. Easiest way to make this rule go away is disable it
  2. second easist is to install the app pools/services it is expecting on every server in the farm. The health rule checks each application pool in the SPWebService ContentService ApplicationPools collection. If it can’t find the Application Pool on the member server is it checking, it will fail and cause this Health Analyzer (HA) item (notice the application pool name(s) are blank in the message).  You can determine the potentially missing Application Pool(s) with the following PowerShell:
$contentService = [Microsoft.SharePoint.Administration.SPWebService]::ContentService
$contentService.ApplicationPools | fl Name


3. Complete Hack, but you can create dummy application pools so the SPHA can find them but they don’t do anything, thus preserving your service isolation on the farm and at the same time keeping the rule intact.

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.