title: How can I change the value of 'Setting' name attribute using powershell script
body: <p>How can I change the value of 'Setting' name attribute using powershell script</p>
  
  <p>XML</p>
  
  <p>**</p>
  
  <pre><code>&lt;ServiceConfiguration serviceName="test" xmlns="http://schemas.microsoft.com/ServiceHosting/2008/10/ServiceConfiguration"&gt;
    &lt;Role name="Role1"&gt;
      &lt;Instances count="1" /&gt;
      &lt;ConfigurationSettings&gt;
        &lt;Setting name="enableCounter" value="true" /&gt;
      &lt;/ConfigurationSettings&gt;
    &lt;/Role&gt;
    &lt;Role name="Role2"&gt;
      &lt;Instances count="1" /&gt;
      &lt;ConfigurationSettings&gt;
        &lt;Setting name="enableCounter" value="true" /&gt;
      &lt;/ConfigurationSettings&gt;
    &lt;/Role&gt;
  &lt;/ServiceConfiguration &gt;
  </code></pre>
  
  <p>**</p>
  
  <p>I've a script like this, it is not working</p>
  
  <pre><code>$serviceconfigpath= "D:\ServiceConfiguration.cscfg"
  $doc = new-object System.Xml.XmlDocument
  $doc.Load($serviceconfigpath)
  
  $testValue= "test"
  
  foreach($n in $doc.selectnodes("/ServiceConfiguration/Role"))
  {
      foreach($n in $doc.selectnode("/ServiceConfiguration/Role/ConfigurationSettings/Setting"))
      {
          switch($n.name)
          {
              "enableCounter" { $n.value = $testValue}
          }
      }
  }
  
  $doc.Save($serviceconfigpath)
  </code></pre>