{"id":1898,"date":"2012-04-11T05:44:04","date_gmt":"2012-04-11T05:44:04","guid":{"rendered":"https:\/\/poiseddevelopers.com\/reality-tech\/?p=1898"},"modified":"2024-05-06T09:53:01","modified_gmt":"2024-05-06T09:53:01","slug":"consolidation-of-application-pools","status":"publish","type":"post","link":"https:\/\/poiseddevelopers.com\/reality-tech\/consolidation-of-application-pools\/","title":{"rendered":"Consolidation of Application Pools"},"content":{"rendered":"<div id=\"ez-toc-container\" class=\"ez-toc-v2_0_65 counter-hierarchy ez-toc-counter ez-toc-grey ez-toc-container-direction\">\n<div class=\"ez-toc-title-container\">\n<p class=\"ez-toc-title \" >Table of Contents<\/p>\n<span class=\"ez-toc-title-toggle\"><a href=\"#\" class=\"ez-toc-pull-right ez-toc-btn ez-toc-btn-xs ez-toc-btn-default ez-toc-toggle\" aria-label=\"Toggle Table of Content\"><span class=\"ez-toc-js-icon-con\"><span class=\"\"><span class=\"eztoc-hide\" style=\"display:none;\">Toggle<\/span><span class=\"ez-toc-icon-toggle-span\"><svg style=\"fill: #999;color:#999\" xmlns=\"http:\/\/www.w3.org\/2000\/svg\" class=\"list-377408\" width=\"20px\" height=\"20px\" viewBox=\"0 0 24 24\" fill=\"none\"><path d=\"M6 6H4v2h2V6zm14 0H8v2h12V6zM4 11h2v2H4v-2zm16 0H8v2h12v-2zM4 16h2v2H4v-2zm16 0H8v2h12v-2z\" fill=\"currentColor\"><\/path><\/svg><svg style=\"fill: #999;color:#999\" class=\"arrow-unsorted-368013\" xmlns=\"http:\/\/www.w3.org\/2000\/svg\" width=\"10px\" height=\"10px\" viewBox=\"0 0 24 24\" version=\"1.2\" baseProfile=\"tiny\"><path d=\"M18.2 9.3l-6.2-6.3-6.2 6.3c-.2.2-.3.4-.3.7s.1.5.3.7c.2.2.4.3.7.3h11c.3 0 .5-.1.7-.3.2-.2.3-.5.3-.7s-.1-.5-.3-.7zM5.8 14.7l6.2 6.3 6.2-6.3c.2-.2.3-.5.3-.7s-.1-.5-.3-.7c-.2-.2-.4-.3-.7-.3h-11c-.3 0-.5.1-.7.3-.2.2-.3.5-.3.7s.1.5.3.7z\"\/><\/svg><\/span><\/span><\/span><\/a><\/span><\/div>\n<nav><ul class='ez-toc-list ez-toc-list-level-1 eztoc-toggle-hide-by-default' ><li class='ez-toc-page-1 ez-toc-heading-level-2'><a class=\"ez-toc-link ez-toc-heading-1\" href=\"https:\/\/poiseddevelopers.com\/reality-tech\/consolidation-of-application-pools\/#Overview\" title=\"Overview\">Overview<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-2'><a class=\"ez-toc-link ez-toc-heading-2\" href=\"https:\/\/poiseddevelopers.com\/reality-tech\/consolidation-of-application-pools\/#Removing_a_Service_Application_Pool\" title=\"Removing a Service Application Pool\">Removing a Service Application Pool<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-2'><a class=\"ez-toc-link ez-toc-heading-3\" href=\"https:\/\/poiseddevelopers.com\/reality-tech\/consolidation-of-application-pools\/#Consolidating_Web_Application_Pools_programmatically\" title=\"Consolidating Web Application Pools programmatically\">Consolidating Web Application Pools programmatically<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-2'><a class=\"ez-toc-link ez-toc-heading-4\" href=\"https:\/\/poiseddevelopers.com\/reality-tech\/consolidation-of-application-pools\/#Consolidating_Service_Application_Pools_programmatically\" title=\"Consolidating Service Application Pools programmatically\">Consolidating Service Application Pools programmatically<\/a><\/li><\/ul><\/nav><\/div>\n<h4>Automated Consolidation of Application Pools<\/h4>\n<p>SharePoint leverages IIS, and runs within Application Pools.\u00a0 One should recognize up front that there are two distinct categories of Application Pools used in SharePoint; Web Application pools and Service Application Pools.<\/p>\n<h2><span class=\"ez-toc-section\" id=\"Overview\"><\/span>Overview<span class=\"ez-toc-section-end\"><\/span><\/h2>\n<p>Application Pools consume an estimated 80-100MB\u00a0RAM each, and possibly a lot more, depending on usage.\u00a0 These appear as w3wp.exe processes in Task Manager.\u00a0 When you have a number of w3wp processes running, it can be hard to tell them apart; which is for a given web or service application?\u00a0 Here\u2019s a way to get the PID (Process ID) for each worker process, along with the user-friendly name, so you can correlate each w3wp process:<\/p>\n<div><\/div>\n<p>&nbsp;<\/p>\n<pre lang=\"php\">c: \r\ncd C:WindowsSystem32inetsrv appcmd.exe list wp\r\n[\/sourcecode ]\r\nA nice listing of Web Application Pools is generated by this single command.  It ensures the fields are not truncated, and is extensible to allow display of any properties\/columns you wish:<\/pre>\n<pre lang=\"php\"> \r\n[sourcecode language=\"powershell\"]\r\nget-SPWebApplication | select displayname, url, applicationpool | format-table -autosize | out-string -width 2000\r\n[\/sourcecode ]\r\nNote the CmdLet \"get-SPWebApplication\".  For Service Application Pools, the CmdLet is \"Get-SPServiceApplicationPool\", as in:\r\n[sourcecode language=\"powershell\"]\r\nGet-SPServiceApplicationPool | select Id, Name, DisplayName, processaccountname\r\n[\/sourcecode ]<\/pre>\n<p>Within IIS, the Service Application Pools are identified by GUID. Their mapping can be explored individually by examining the application pool binding, but this is a bit laborious.<\/p>\n<h2><span class=\"ez-toc-section\" id=\"Removing_a_Service_Application_Pool\"><\/span>Removing a Service Application Pool<span class=\"ez-toc-section-end\"><\/span><\/h2>\n<p>To remove a Service Application Pool by name, you can use: [sourcecode language=&#8221;powershell&#8221;] Remove-SPServiceApplicationPool -Identity &#8220;Your Orphaned SharePoint Service Application Pool Name&#8221;<\/p>\n<p>[\/sourcecode ]<br \/>\nMy own preference is to first consolidate the application pools, then in IIS quiesce the desired application pools, and only once things are truly running smoothly, they can be removed. It is important to do the removing and adding in PowerShell and not directly in IIS. This will ensure that the correct IIS configuration gets propagated to all current and future WFEs (Web Front Ends).<\/p>\n<h2><span class=\"ez-toc-section\" id=\"Consolidating_Web_Application_Pools_programmatically\"><\/span>Consolidating Web Application Pools programmatically<span class=\"ez-toc-section-end\"><\/span><\/h2>\n<p>Consolidating Web Application Polls is quite easy. If you do not have security driven segregation of Application Pools, you can consider doing so. Note I have received conflicting advice on doing this. Todd Klindt who I hold in the highest regard recommends considering consolidation. Microsoft does advise quite a low maximum number of Application Pools, yet their support staff have advised segregation.<\/p>\n<p>First let&#8217;s grab an existing Application Pool, and simply reassign it to the target Web Application Pool:<\/p>\n<pre lang=\"php\">[sourcecode language=\"powershell\"]\r\n$sourceWebAppPool = (Get-SPWebApplication &lt; URL of a webapp whose application pool you want to use&gt;).ApplicationPool\r\n$webApp = Get-SPWebApplication &lt; URL of the web application you want to change&gt;\r\n$webApp.ApplicationPool = $sourceWebAppPool\r\n$webApp.ProvisionGlobally()\r\n$webApp.Update()<\/pre>\n<p>iisreset<\/p>\n<p>Lather, rinse, and repeat for each of your Web Apps to be consolidated\u2026<\/p>\n<p>Note that there is no SharePoint CmdLet for creating an Application Pool.\u00a0 You can use the IIS CmdLet, but I am not convinced this is a safe method, as right away I can see the service account is an IIS Service Identity reference, and the application pools have a different type and cannot be assigned to a web application directly.\u00a0\u00a0 here\u2019s the CmdLet for reference:<\/p>\n<p data-uw-rm-sr=\"\">Import-Module WebAdministration<br role=\"presentation\" data-uw-rm-sr=\"\" \/>$appPool = New-WebAppPool \u201cMy new App Pool\u201d<br role=\"presentation\" data-uw-rm-sr=\"\" \/>[\/sourcecode ]<br role=\"presentation\" data-uw-rm-sr=\"\" \/>If you need to segregate previously consolidated web application application pools, the following round-about procedure is safe and works:<\/p>\n<ol>\n<li>Create a brand new temporary Web Application and associated pool<\/li>\n<li>Reassign your target web app\u2019s pool, as described above<\/li>\n<li>Destroy the temporary Web Application<\/li>\n<\/ol>\n<p>The sequence is key.\u00a0 If you destroy the temporary web application, the associated pool is destroyed with it, because there are no other associated applications.\u00a0 In contrast, once you assign a second web application to this new application pool, the application pool will not be destroyed when the temporary web application is removed.<\/p>\n<h2><span class=\"ez-toc-section\" id=\"Consolidating_Service_Application_Pools_programmatically\"><\/span>Consolidating Service Application Pools programmatically<span class=\"ez-toc-section-end\"><\/span><\/h2>\n<p>On some farms I\u2019ve inherited, there is\u00a0a profusion of unnecessary Service Application Pools.\u00a0 Note there are reasons to isolate distinct service application pools, generally around security and multi-tenancy.<\/p>\n<p>I wanted to consolidate my Service application pools\u00a0but in a safe and programmatic manner.\u00a0 While you can change the account associated with a service application, there is the risk that the new service account won\u2019t quite have the necessary access.\u00a0 When SharePoint does automatically grant access to the new service account, it won\u2019t remove access from the original service account.\u00a0 Lastly, one needs to make sure the new service account is configured as a managed account.\u00a0 Lastly, SharePoint doesn\u2019t support managed service accounts for all service applications.\u00a0 Exceptions do include the User Profile Service ADSync\u00a0account, unattended user accounts (Excel, Visio, PerformancePoint), search crawl accounts (Foundation, Enterprise, and FAST), and the two Object Cache Portal Accounts (which are configured for each Web Application for performance reasons).<\/p>\n<p>Not every Service Application runs under an Application Pool; some run under the Farm\u2019s pool, and hence can\u2019t be directly reassigned. Farm-wide service applications have one and only one instance in the farm.\u00a0 So the Security Token Service Application, Web Usage Application (WS_UsageApplication), State Service and Application Registry Service Application don\u2019t run under their own Application Pools, and their CmdLets are simpler.\u00a0 So while one can create multiple Session State Service Applications and corresponding databases, there\u2019s only one State Service Application.\u00a0 The script below lists them by name in an array and makes sure not to even try to remap these.\u00a0 For good measure I include the FAST Content Service Application in this category.\u00a0 Note yours may be named differently.<\/p>\n<p>Next, I wanted to start with a clean Service Application Pool named clearly denoting the desired service account.<\/p>\n<p>&nbsp;<\/p>\n<pre lang=\"php\">$MyRefAppPool=new-spserviceapplicationpool -name \u201cSPService Service Application Pool\u201d -account \u201cYourDomainspservice\u201d\r\n$SPaps = get-spserviceapplication\r\nfor ($i=0;$i -lt $SPaps.Count; $i++)\r\n{\r\n$SPap = $SPaps[$i];     \r\n#Some service applications run at the farm level and don\u2019t have selectable application pools, hence is it wiser to filter these out up front.\r\nif (@(\u201cSecurityTokenServiceApplication\u201d,\u201dApplication Registry Service \u201c,\u201dFASTContent\u201d,\u201dState Service\u201d,\u201dWSS_UsageApplication\u201d,\u201d\u201d) -notcontains $SPAP.DisplayName)\r\n{\r\ntry\r\n{\r\n$testAppPool=$SPAp.get_applicationpool();\r\n#Don\u2019t mix &amp; match the application pools and accounts, best is to consolidate along the lines of existing process accounts, to avoid permissions issues\r\nif ($testAppPool.ProcessAccountname -eq $MyRefAppPool.processaccountname)\r\n{\r\nwrite-host \u201cProcessing  $($SPAp.name) because it has the target process account: $($MyRefAppPool.processaccountname)\u201d\r\n$SPAp.set_applicationpool($MyRefAppPool)\r\n$SPAp.update()  #update() is actually required.  You will notice a processing delay during the update\r\n}\r\nelse\r\n{\r\nwrite-host \u201cSkipping $($SPAp.name) because it has a different process account: $($SPAp.get_applicationpool().ProcessAccountname)\u201d\r\n}\r\n}\r\ncatch\r\n{\r\n$testAppPool=$null;\r\nwrite-host \u201cSkipping $($SPAp.name) because it had an error\u201d\r\n}\r\n}\r\n}\r\n[\/sourcecode ]<\/pre>\n<p>An IISReset at this point is advisable. Lastly, you can go into IIS after running this, view Application pools, and \u201cStop\u201d the GUID named Application Pools with zero associated Applications. Another IISReset is advisable to ensure you are recovering your RAM.<\/p>\n<p>For a more general overview of Application Pool configuration, please see TechNet.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>Automated Consolidation of Application Pools SharePoint leverages IIS, and runs within Application Pools.\u00a0 One should recognize up front that there are two distinct categories of Application Pools used in SharePoint; Web Application pools and Service Application Pools. Overview Application Pools consume an estimated 80-100MB\u00a0RAM each, and possibly a lot more, depending on usage.\u00a0 These appear [&hellip;]<\/p>\n","protected":false},"author":13,"featured_media":1899,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"_acf_changed":false,"footnotes":""},"categories":[38],"tags":[],"class_list":["post-1898","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-ils"],"acf":[],"_links":{"self":[{"href":"https:\/\/poiseddevelopers.com\/reality-tech\/wp-json\/wp\/v2\/posts\/1898","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/poiseddevelopers.com\/reality-tech\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/poiseddevelopers.com\/reality-tech\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/poiseddevelopers.com\/reality-tech\/wp-json\/wp\/v2\/users\/13"}],"replies":[{"embeddable":true,"href":"https:\/\/poiseddevelopers.com\/reality-tech\/wp-json\/wp\/v2\/comments?post=1898"}],"version-history":[{"count":4,"href":"https:\/\/poiseddevelopers.com\/reality-tech\/wp-json\/wp\/v2\/posts\/1898\/revisions"}],"predecessor-version":[{"id":3480,"href":"https:\/\/poiseddevelopers.com\/reality-tech\/wp-json\/wp\/v2\/posts\/1898\/revisions\/3480"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/poiseddevelopers.com\/reality-tech\/wp-json\/wp\/v2\/media\/1899"}],"wp:attachment":[{"href":"https:\/\/poiseddevelopers.com\/reality-tech\/wp-json\/wp\/v2\/media?parent=1898"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/poiseddevelopers.com\/reality-tech\/wp-json\/wp\/v2\/categories?post=1898"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/poiseddevelopers.com\/reality-tech\/wp-json\/wp\/v2\/tags?post=1898"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}