Update configSource of XML element in web.config using Powershell by passing in Parameters

前端 未结 2 1646
长情又很酷
长情又很酷 2021-01-07 04:26

I am trying to figure out a way to update my web.config for different environments by updating the configSource for the appSettings element in the web.config.

Here

相关标签:
2条回答
  • 2021-01-07 05:11

    Finally figured it out.

    $root = $xml.get_DocumentElement().SelectSingleNode("//client[@configSource]").configSource = "test"
    

    of course, I will replace "//client[@configSource]" with a variable so I can pass in different nodes as parameters to create my base script.

    0 讨论(0)
  • 2021-01-07 05:18

    Im looking for a way to modify the code as well.

    Here is a way you can view whats the node:

    $path = 'c:\site\web.config'
    $PublishState = (Select-Xml -Path $path -XPath "configuration/appSettings/add[@key='PublishState']/@value").Node.'#text'
    $PublishState
    
    0 讨论(0)
提交回复
热议问题