Monday, April 27, 2015

SharePoint 2013: how to add and remove web application pools

Introduction

This posting integrates postings and comments by  Brendan Griffin and Henrik T√łnnessen and consolidates my notes on this topic. It assumes that the account you will be using for the new web application pool identity is a managed account.

Add a new web application pool and assign to web application
  1. Review
    1. Log into a SharePoint 2013 server using the SharePoint Setup User Administrator account (eg, spAdmin). This is the same account that you (should have) used to perform the initial farm installation and configuration.
      This is important in that the changes you will be making will be to the farm configuration database; and, by default, only this account has the privileges necessary to make such changes.
    2. Launch an elevated SharePoint Management shell.
    3. Execute the following commands, making appropriate revisions:
      ([Microsoft.SharePoint.Administration.SPWebService]::ContentService).ApplicationPools | Sort-Object Name | Select-Object Name, ID, UserName, Status, parent | Format-Table -Auto
  2. Create
    1. Now, using the same management shell, execute the next few commands to create the new pool:
      $WebAppURL = "[Your site URL]" $NewAppPoolName = "[NameOfNewAppPool]" $NewAppPoolIdentity = "[IdentityOfnewAppPool]" $Password = Read-Host -Prompt "Enter the service account password: " -AsSecureString $Service = [Microsoft.SharePoint.Administration.SPWebService]::ContentService $NewAppPool = New-Object Microsoft.SharePoint.Administration.SPApplicationPool($NewAppPoolName,$Service) $NewAppPool.CurrentIdentityType = "SpecificUser" $NewAppPool.Username = $NewAppPoolUserName $NewAppPool.SetPassword($Password) $NewAppPool.Provision() $NewAppPool.Update($true) $NewAppPool.Deploy()
      The new application pool will be available immediately.
  3. Verify
    1. Log into one of the farm WFEs hosting the web application using any administrator account.
    2. Launch IIS Manager.
    3. In the Connections tree, expand Application Pools.
Remove an existing web application pool
  1. Review
    1. Log into a SharePoint 2013 server using the SharePoint Setup User Administrator account (eg, spAdmin). This is the same account that you (should have) used to perform the initial farm installation and configuration.
      This is important in that the changes you will be making will be to the farm configuration database; and, by default, only this account has the privileges necessary to make such changes.
    2. Launch an elevated SharePoint Management shell.
    3. Execute the following commands, making appropriate revisions:
      ([Microsoft.SharePoint.Administration.SPWebService]::ContentService).ApplicationPools | Sort-Object Name | Select-Object Name, ID, UserName, Status, parent | Format-Table -Auto
    4. Identity the name of the web application pool you want to remove.
    5. Copy this name.
  2. Remove
    1. Now, using the same management shell, execute the following command to remove the web application pool.
      $apppool = [Microsoft.SharePoint.Administration.SPWebService]::ContentService.ApplicationPools | where {$_.Name -eq "[name of web application pool]"} $apppool.UnProvisionGlobally()
      This executes as a job and will take a minute or two to complete.
  3. Verify
    1. Log into one of the farm WFEs hosting the web application using any administrator account.
    2. Launch IIS Manager.
    3. In the Connections tree, expand Application Pools.
References
  • The new web application pool will not be added to the  application pools associated with web applications until you execute the Update method.  You can test this by executing all of the commands up to but not including the Update method, and then listing out the web application pools.  Additionally, you will not see the new application pool show up in IIS Manager until after you execute the Deploy method.
  • The Remove method of [Microsoft.SharePoint.Administration.SPWebService]::ContentService.ApplicationPools object appears to only remove the web application pool from the farm configuration database and not also from IIS.  On the other hand, the UnprovisionGlobally method of an SPApplicationPools object removes the application pool both from SharePoint and IIS.
  • If you get an instance of the SPApplicationPools object and review its members, note that there is a Provision method but that this method does not push the update to the WFEs.  On the other hand, the UnprovisionGlobally method of this object does touch both SharePoint configuration and IIS, updating both.  This seems inconsistent.
  • Thanks to Brendan Griffin and Henrik T√łnnessen for helpful presentations on this topic.

No comments: