Adding tag in Web.config RRS feed

  • Question

  • Dear All,

    In my web.config I want to add the following tags through Windows Powershell Script

    this tag should go between <assemblies></assemblies>
    <add assembly="System.Net.Http, Version=, Culture=neutral, PublicKeyToken=B03F5F7F11D50A3A" />

    This tag should go between <handlers></handlers>
    <remove name="ExtensionlessUrlHandler-Integrated-4.0" />
    <add name="ExtensionlessUrlHandler-Integrated-4.0" path="/v1/*" verb="GET,POST,DELETE" type="System.Web.Handlers.TransferRequestHandler"preCondition="integratedMode,runtimeVersionv4.0" />

    I have started to write script but I could only go this far

    $webConfig = '.\web.config'
    [xml]$web =  (Get-Content $webConfig)

    Any help would be greatly appreciated

    Wednesday, February 13, 2019 5:37 PM

All replies

  • You can manage the web.config file using the utilities  command AppCmd.exe:


    Post issues with editing web.config files in the http://forums.iis.net or in http://forums.asp.net . These are the correct forums for IIS and they also support the IIS PowerShell methods.

    You can also edit the file using the "XML" type I PowerShell but this requires a correct knowledge of the schema and of XML.


    • Proposed as answer by BOfH-666 Wednesday, February 13, 2019 7:13 PM
    Wednesday, February 13, 2019 7:02 PM
  • What JRV said.

    But if you really want to mess around with XML, here's a little snippet of code that does what you want with the <Assemblies> section:

    [xml]$xml = get-content c:\test\web.config
    $elem = $xml.configuration.Assemblies.AppendChild($xml.CreateNode([System.Xml.XmlNodeType]::Element,'Add', $null))
    $elem.SetAttribute('assembly',"System.Net.Http, Version=, Culture=neutral, PublicKeyToken=B03F5F7F11D50A3A")

    --- Rich Matheisen MCSE&I, Exchange Ex-MVP (16 years)

    Wednesday, February 13, 2019 7:08 PM
  • Hi,

    Was your issue resolved?

    If you resolved it using our solution, please "mark it as answer" to help other community members find the helpful reply quickly.

    If you resolve it using your own solution, please share your experience and solution here. It will be very beneficial for other community members who have similar questions.

    If no, please reply and tell us the current situation in order to provide further help.

    Best Regards,


    Just do it.

    Thursday, February 28, 2019 2:23 PM