Last modified at 3/16/2014 12:13 PM by Koen Zomers

When working with SPWebConfigModification entries to add settings to web.config files on SharePoint 2010 farms, you might run into the situation where these are not functioning correctly anymore. Either the entries are not being added anymore or old values from many versions back are still being pushed into the web.config files. I've seen many strange solutions to this problem on blogs on the internet. Some even proposed hacking the SharePoint database to get those values out. That is obviously very unwise to do so and will bring your installation in a no longer supported situation by Microsoft.

There is an easy way to accomplish the same using the allmighty PowerShell. Follow the steps below to get rid of those corrupt SPWebConfigModification entries:

  1. Open up a Powershell window under the Administrator priviledges on one of your SharePoint servers in the farm having the corruption
  2. Load the SharePoint snapin by entering:

    Add-PSSnapin Microsoft.SharePoint.PowerShell


  3. Now enter the following command to get an instance of your SPWebApplication:

    $w = Get-SPWebApplication -Identity http://<url to your SharePoint site>


  4. Now enter the following command to show a list with all active SPWebConfigModifications:


    You should see a list with SPWebConfigModifications containing your corrupt ones.

  5. Now if you want to remove all entries, simply execute:


    However if you want to remove a specific one, enter:

    $wcm = $w.WebConfigModifications | Where { $_.Name -eq "<name of entry to remove>" }

    i.e. to remove the third one listed above:

    $wcm = $w.WebConfigModifications | Where { $_.Name -eq "add[@key='ExcelServiceURL']" }


  6. Execute the following command to apply the updated values:


  7. Now go into Central Administration, go to Application Management and go to Manage web applications

  8. Click on the row representing your SharePoint webapplication and click on Manage Features in the ribbon


  9. Disable the feature you created to perform your webconfig modifications


  10. After confirming you want to disable it, enable it again and the new correct values should be written to the web.config file. You can confirm this by calling $w.WebConfigModifications again which should now list the new proper entires.