Editing Web Config file using Microsoft PowerShell

前端 未结 1 2001
离开以前
离开以前 2020-12-31 22:46

i want to modify my web config file using powershell . i stuck in somewhere . i want to update appsettings and also connectionsstring information at the same time when i cha

1条回答
  •  甜味超标
    2020-12-31 23:12

    $webConfig = "C:\Inetpub\Wwwroot\application\web.config"
    $doc = (gc $webConfig) -as [xml]
    $doc.SelectSingleNode('//appSettings/add[@key="mykey1"]/@value').'#text' = 'true'
    $doc.SelectSingleNode('//connectionStrings/add[@name="myname1"]/@connectionstring').'#text' = 'my_string'
    $doc.Save($webConfig)
    

    You can use XPath to select your nodes and set their value via the #text property PowerShell adds.

    Note - your example xml has problems with casing and some typos. Here is what I tested with:

    
        
             
        
        
            
        
    
    

    0 讨论(0)
提交回复
热议问题