Changing the Application Pool on a Web Application the right way

I was working a farm today that had 10 web applications, all with their own application pool.  As we know from http://technet.microsoft.com/en-us/library/cc262787.aspx#WebserverAppServer , the recommended limit is 10 application pools per WFEs and with the addition of the Web Services App pool, the CA app pool and others, we were over our limit.  Our performance was suffering and we needed a way to consolidate the web application app pools.

Before SharePoint, we'd just open IIS Manager and update the application pool.  But now that's not the correct way: SharePoint doesn't know anything about the change.  Imagine in 2 years from now when you add another WFE - SharePoint would think that we have 10 application pools and would provision them all on the new WFE correctly.  Then you'd have to go in and change them.  What a maintenance nightmare this would be!

To do it correctly, we'll leverage this PowerShell snippet:

$sourceWebAppPool = (Get-SPWebApplication < URL a webapp who’s application pool you want to use>).ApplicationPool

$webApp = Get-SPWebApplication < URL of the web application you want to change>

$webApp.ApplicationPool = $sourceWebAppPool

$webApp.ProvisionGlobally()

$webApp.Update()

iisreset

 

Here's an example:
 

In my environment, I have 2 web applications: //VM-SP2010:26927 and //VM-SP2010:4150.  I want :26972 to use the same application pool as :4150.  So my PS is:

$sourceWebAppPool = (Get-SPWebApplication http://VM-SP2010:4150).ApplicationPool

$webApp = Get-SPWebApplication http://VM-SP2010:26927

$webApp.ApplicationPool = $sourceWebAppPool

$webApp.ProvisionGlobally()

$webApp.Update()

IISReset

 

Before:

 

And After:


    
  
  

 

Now the change is saved in the config DB and any new WFEs we add will have the correct settings.

 

HTH