title: Editing Web Config file using Microsoft PowerShell
body: <p>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 change them in powershel</p>
  
  <p>I have this code but it changes only apppsettings value when i change it here and run it but i also want to include connectionstring here. How can i achieve it ?</p>
  
  <pre><code>$webConfig = "C:\Inetpub\Wwwroot\application\web.config"
  $doc = new-object System.Xml.XmlDocument
  $doc.Load($webConfig)
  $doc.get_DocumentElement()."appsetting".add[0].value = "true"
  $doc.Save($webConfig)
  </code></pre>
  
  <p>Here is my web config file</p>
  
  <pre><code> &lt;appSettings&gt;
       &lt;add key="mykey1" value="false"/&gt;
       &lt;add key="mykey2" value="true"/&gt;
       &lt;add key="mykey3" value="false"/&gt;
  &lt;/appSettings&gt;
  
    &lt;connectionstrings&gt;
  
    &lt;add name="myname1" connectinstring="Data Source=ABDULLAH-PC\SQLEXPRESS;Initial Catalog=UserDataBase;
    Integrated Security=True" providerName="System.Data.SqlClient" /&gt;
    &lt;add name="myname2" connectinstring="myconnectionstring2" /&gt;
     &lt;add name="myname3" connectinstring="myconnectionstring3" /&gt;
   &lt;/connectionStrings&gt;
  </code></pre>
  
  <p>Here i want to upadate appsettings -( key and value) and also connectionstrings( name and initialcatalog)
  at the same time</p>
  
  <p>when i tried your code it gives me this error</p>
  
  <pre><code>Property '#text' cannot be found on this object; make sure it exists and is settable.
  At line:3 char:66
  + $doc.SelectSingleNode('//appSettings/add[@key="mykey1"]/@value'). &lt;&lt;&lt;&lt; '#text' = 'false'
  + CategoryInfo          : InvalidOperation: (#text:String) [], RuntimeException
  + FullyQualifiedErrorId : PropertyNotFound
  
  Property '#text' cannot be found on this object; make sure it exists and is settable.
  At line:4 char:85
  + $doc.SelectSingleNode('//connectionStrings/add[@name="myname1"]/@connectionstring'). &lt;&lt;&lt;&lt; '#text'='my_string'       
    + CategoryInfo          : InvalidOperation: (#text:String) [], RuntimeException
     + FullyQualifiedErrorId : PropertyNotFound
  </code></pre>