Background
Some custom SharePoint products make changes to the web.config file for a Web application via SPWebConfigModification objects to support their features. Bamboo products sometimes make changes like this during installation. Please see How to modify a web.config file using PowerShell for some additional background information.
You may need to remove these changes for a particular Web application, if the product is no longer used on that Web application. It’s not a good idea to manually edit the file to remove the text, because the web.config would no longer match what has been set in the SharePoint configuration database and might cause future problems on your farm.
Resolution
Follow the steps below to remove web.config settings using PowerShell.
NOTE: The commands in this article work with both SharePoint 2010 Foundation and Server. Be extra careful when making changes to the web.config. Back up the file before making any changes. Do not remove a modification unless you are absolutely sure what it is.
Step | Action |
---|---|
1. | First, open SharePoint 2010 Management Shell. From the Start menu on a SharePoint WFE Server, select All Programs > Microsoft SharePoint 2010 Products > SharePoint 2010 Management Shell |
2. |
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 by Bamboo products to support Telerik: |
3. |
Now, we can identify a particular modification and remove it using the commands shown below.
In this example, we’ll remove the modification with the name “add[@name=[‘Session’]” and path “configuration/system.webServer/Modules”. |
4. |
The ApplyWebConfigModifications() method applies this change across the farm for the specific web application, 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 by Bamboo Telerik Config in a particular Web application (they all have the same Owner value):
|