locked
Powershell - webconfig RRS feed

  • Question

  • Hi I am trying to make changes to the web.config file using powershell. I have found blogs on the forum, to get started, but I got stuck now.

    This part work:

       

    $myHandlerWebApplication = "http://app01:32798/"

    $sharePointDLL = $ENV:CommonProgramFiles+("\Microsoft Shared","Web Server Extensions","15","ISAPI" -join "\") + "\Microsoft.SharePoint.dll"
    [System.Reflection.Assembly]::LoadFile($sharePointDLL) | Out-Null

    $webapp = [Microsoft.SharePoint.Administration.SPWebApplication]::Lookup($myHandlerWebApplication)
    $assembly = "MyAuthenticationProvider, Version=15.0.0.0, Culture=neutral, PubliceKeytoken=71e9bce111e9429c"

    $connectionPath = New-Object "Microsoft.SharePoint.Administration.SPWebConfigModification"
    $connectionPath.Path = "configuration/system.web/membership/providers"
    $connectionPath.Name = "add[@name='MyAuthenticationProvider'][@type='MyAuthenticationProvider.MyMembershipProvider, " + $assembly + "']"
    $connectionPath.Sequence = 0
    $connectionPath.Owner = "MyAuthenticationProvider"
    $connectionPath.Type = 0
    $connectionPath.Value = "<add name='FBA_User' connectionStringName='Testconn''' />"

    $webApp.WebConfigModifications.Add($connectionPath)

    $webapp.Update()
    $webapp.Parent.ApplyWebConfigModifications()

    Now I would like to add an entry under "Config/system-serviceModel/ and tried adding this

    $CustomTest = New-Object "Microsoft.SharePoint.Administration.SPWebConfigModification"
    $CustomTest.Path = "system.serviceModel/bindings"
    $CustomTest.Name = "add[@name='CustomTestName'][@type='CustomTestName']"
    $CustomTest.Sequence = 0
    $CustomTest.Type = 0
    $CustomTest.Owner = "KMDName"
    $CustomTest.Value = "<binding name='Test'>"

    But nothing happens, can anyone help?

    Regards

    Thomas

    Monday, January 5, 2015 10:26 AM

Answers

All replies

  • Hi Thomas,

    This should help you

    https://blogs.blackmarble.co.uk/blogs/rhepworth/post/2014/07/01/Safely-modify-SharePoint-2013-WebConfig-files-using-PowerShell.aspx

    http://social.technet.microsoft.com/wiki/contents/articles/19669.sharepoint-2013-how-to-edit-the-web-config-using-powershell.aspx

    http://blogs.technet.com/b/heyscriptingguy/archive/2010/09/14/use-powershell-to-script-changes-to-the-sharepoint-web-config-file.aspx


    Please remember to click 'Mark as Answer' on the answer if it helps you

    • Proposed as answer by SekThang Monday, January 5, 2015 11:12 AM
    Monday, January 5, 2015 11:08 AM
  • Hi Thomas,

    This should help you

    https://blogs.blackmarble.co.uk/blogs/rhepworth/post/2014/07/01/Safely-modify-SharePoint-2013-WebConfig-files-using-PowerShell.aspx

    http://social.technet.microsoft.com/wiki/contents/articles/19669.sharepoint-2013-how-to-edit-the-web-config-using-powershell.aspx

    http://blogs.technet.com/b/heyscriptingguy/archive/2010/09/14/use-powershell-to-script-changes-to-the-sharepoint-web-config-file.aspx


    Please remember to click 'Mark as Answer' on the answer if it helps you

    On top of Lakshman, you try the below links also.

    https://social.technet.microsoft.com/Forums/windowsserver/en-US/9e644edd-2e62-4d01-84e0-95fdd67b2055/modify-web-config-using-powershell?forum=winserverpowershell

    http://serverfault.com/questions/585841/modify-iis-web-config-using-powershell

    http://blogs.msdn.com/b/sonam_rastogi_blogs/archive/2014/08/18/update-configuration-files-using-powershell.aspx

    If its not helping, please let us know


    Sekar - Our life is short, so help others to grow

    Whenever you see a reply and if you think is helpful, click "Alternate TextVote As Helpful"! And whenever you see a reply being an answer to the question of the thread, click "Alternate TextMark As Answer

    Monday, January 5, 2015 11:20 AM
  • Hi

    Sorry none of the links above gave me any answers. I can easily use the script that is linked to the Blobcache, but i need to get entries into <System.servicemodel>... And nothing happens here.

    Monday, January 5, 2015 11:46 AM
  • Hi,

     According your reply, please refer the below link which will help you to resolve your issue.

    http://stackoverflow.com/questions/10342657/how-can-i-add-a-section-to-a-web-config-using-powershell

    If not please let us know


    Sekar - Our life is short, so help others to grow

    Whenever you see a reply and if you think is helpful, click "Alternate TextVote As Helpful"! And whenever you see a reply being an answer to the question of the thread, click "Alternate TextMark As Answer

    Monday, January 5, 2015 11:59 AM
  • Hi that solution could work. But I need a solution that can be run during deployment, so that all changes are made on all the web servers, so I dont have to change the web.config file on each server.
    Monday, January 5, 2015 1:10 PM
  • Hi,

    For updating Multiple Front-End Servers Web Configuration, you can refer to the blog:

    http://www.c-sharpcorner.com/UploadFile/40e97e/updating-multiple-front-end-servers-configuration-in-sharepo/

    Thanks,

    Eric

    Forum Support

    Please remember to mark the replies as answers if they help and unmark them if they provide no help. If you have feedback for TechNet Subscriber Support, contact tnmff@microsoft.com.


    Eric Tao
    TechNet Community Support

    Tuesday, January 6, 2015 9:54 AM