SharePoint and Web.config modifications

By | 2010-08-25

Ever since MOSS 2007 we all know the Web.Config Modifications Manager within the SharePoint API. But today I stumbled upon this PowerShell commandlet: Add-WebConfiguration. This commandlet is from the IIS7(.5) powershell module WebAdministration.

The short version is, you can use this in you deploy script to do Web.Config modifications

Example for an AppSettings Configuration Key:”

This will result in the following addition of your Web.Config.

Note: Be carefull with ANY Web.Config modification, you can break stuff!
Load the WebAdministration module in powershell:

4 thoughts on “SharePoint and Web.config modifications

  1. Mike

    Thank you for your post. It is the most useful thing I have found regarding using PowerShell to edit the web.config file.

    Unfortunately, when I run this:

    Add-WebConfiguration /system.web/membership/providers “IIS:sites[site name]” -value @{name=”FBAMembershipProvider”;
    type="System.Web.Security.SqlMembershipProvider, System.Web, Version= 2.0.0.0, Culture= neutral, PublicKeyToken= b03f5f7f11d50a3a";

    connectionStringName=”FBAconn”;`
    applicationName=”/”}

    it adds the new provider element, but it only has a name and a type, it does not have the connectionStringName or the applicationName attributes.

    Do you have any suggestions?

    Reply
  2. Mike

    Thank you for your post. It is the most useful thing I have found regarding using PowerShell to edit the web.config file.

    Unfortunately, when I run this:

    Add-WebConfiguration /system.web/membership/providers “IIS:sites[site name]” -value @{name=”FBAMembershipProvider”;
    type="System.Web.Security.SqlMembershipProvider, System.Web, Version= 2.0.0.0, Culture= neutral, PublicKeyToken= b03f5f7f11d50a3a";

    connectionStringName=”FBAconn”;`
    applicationName=”/”}

    it adds the new provider element, but it only has a name and a type, it does not have the connectionStringName or the applicationName attributes.

    Do you have any suggestions?

    Reply
  3. Koen van der Linden

    Looks good, but I think this only updates the current Web Application that’s running on the box. What about the web.configs on the other Web Front End servers in the SharePoint farm.

    Reply
  4. Stef van Hooijdonk Post author

    You are right, have been meening to write a proper sharepoint custom tumer job for it!

    Reply

Leave a Reply

Your email address will not be published. Required fields are marked *