SharePoint 2010 Cookbook: How to Remove a web.config Modification Using PowerShell

Some custom SharePoint products make changes to the web.config of a Web application via SPWebConfigModification objects to support their features. Sometimes, we need to remove these changes for a particular Web application (usually because the custom product is never used on this Web application), but it’s not a good idea to manually remove the text, because the web.config would not match what has been set in the configuration database and might cause problems. In this article, I will demonstrate how to properly remove these web.config settings using PowerShell.


How can I remove a web.config modification properly using PowerShell?


First, open SharePoint 2010 Management Shell. From the Start menu, select All Programs > Microsoft SharePoint 2010 Products > SharePoint 2010 Management Shell:

Next, list all of the SPWebConfigModification objects that have been applied to the Web application. These objects are stored in the WebConfigModifications property of the Web application. In this example, you can see some of the modifications added Bamboo products to support Telerik:

   1: $webApp = Get-SPWebApplication WebApplicationURL
   2: $webApp.WebConfigModifications

Now, we can identify a particular modification and remove it using the commands shown below. In this example, I’ll try to remove the modification with name “add[@name=[‘Session’]” and path “configuration/system.web/httpModules”:

   1: $config = $webApp.WebConfigModifications | Where-Object {condition_to_identify_the_object}
   2: $webApp.WebConfigModifications.Remove($config)
   3: $webApp.Update()
   4: $webApp.Parent.ApplyWebConfigModifications()

The ApplyWebConfigModifications() method applies this change across the farm, so we don’t need to worry about each physical web.config file at the server-level. That is one of the main advantages of using PowerShell to update web.config modifications.

If there are multiple modifications we need to remove, we can use a loop to do that. The following example removes all of the modifications added Bamboo Telerik Config in a particular Web application (they all have the same Owner value):

   1: $BambooConfigs  = $webApp.WebConfigModifications | Where-Object {$_.Owner -eq "Bamboo.SP2010.Config"}
   2: foreach ($config in $BambooConfigs) {
   3:     $webApp.WebConfigModifications.Remove($config)
   4: }
   5: $webApp.Update()
   6: $webApp.Parent.ApplyWebConfigModifications()


  • The commands in this article work with both SharePoint 2010 Foundation and Server.
  • Be extra careful when making changes to the web.config. Do not remove a modification unless you are absolutely sure what it is.

See Also:

All SharePoint Versions

The web parts are functional components that extend your SharePoint environment whether it’s hosted, on-premises, or part of Microsoft® Office 365.

SharePoint 2013, 2016, 2019, Online (Office 365)

On-Premises Only

These web parts extend SharePoint beyond its out-of-the-box capabilities by tailoring it to your requirements with Bamboo Solution’s growing portfolio of SharePoint Web Parts.

SharePoint 2013, 2016, 2019


Product Suites

Experience greater power and savings by bundling our SharePoint apps and web parts.

Essentials Suite

Essentials Plus Suite

Bamboo Premier Suite

Project Management Suite

Knowledge Management Suite

External User Manager


For more information on our product suites, contact us.

Featured Services

SharePoint Health Check

A SharePoint Health Check will identify the causes of issues and risks associated with your specific environment, and is custom tailored to provide you with the best recommendations to optimize your SharePoint environment.

SQL Health Check

Document recommendations relating to performance, stability, availability, or a specific focus you request of your SQL Server database instances.

My SharePointXperts

The truth is that each SharePoint skill may not be a full time job for many organizations, and it is nearly impossible for one person to do everything you need – so augment your team with SharePointXperts; providing the skill sets you need when you need them!