title: using regex in powershell script to replace value of a key/value tags
body: <p>using powershell script, I need to update some values inside an xml file. The xml is a list of keys and values.</p>
  
  <p>More specifically i need to look for the key "servername" and update the relevant value tag with the $myservername. Also to look for the key "serverport" and update the relevant value tag with $myport.</p>
  
  <p>how can this be done using powershell scripting?</p>
  
  <p>i thought of using simple regex replace command as follows</p>
  
  <pre><code>$myservername = "some-server"
  $myport = "8888"
  $localFile = "C:\_Temp\Files\20190822115503\Manifest.xml"
  $content = (Get-Content $localFile) 
  
  
  $newcontent = $content -replace '"&lt;Key&gt;servername&lt;/Key&gt;\s*&lt;Value&gt;(value1)&lt;/Value&gt;"', $myservername
  
  
  $newcontent = $content -replace '"&lt;Key&gt;serverport&lt;/Key&gt;\s*&lt;Value&gt;(value1)&lt;/Value&gt;"', $myport
  </code></pre>
  
  <p>The following is just a partial block of the xml file:</p>
  
  <pre><code>    &lt;Properties&gt; 
         &lt;ManifestProperty ValueType="string"&gt;
           &lt;Key&gt;servername&lt;/Key&gt;
           &lt;Value&gt;value1&lt;/Value&gt;
         &lt;/ManifestProperty&gt;
         &lt;ManifestProperty ValueType="string"&gt;
           &lt;Key&gt;serverport&lt;/Key&gt;
           &lt;Value&gt;value2&lt;/Value&gt;
         &lt;/ManifestProperty&gt;
      &lt;/Properties&gt;
  </code></pre>
  
  <p>We need to search for the "key" and then replace the "value"</p>