title: How do I replace a line in a file using PowerShell?
body: <p>I am trying to read replace a line in a configuration file using PowerShell. Sometimes this script works, but most of the time it does not replace the line.</p>
  
  <pre><code>(Get-Content D:\home\App_Config\Sitecore.config) `
      | %{ $_ -replace '  &lt;setting name="Media.MediaLinkServerUrl" value=" "/&gt;',' &lt;setting name="Media.MediaLinkServerUrl" value="https://newurl.com"/&gt;'} `
      | Set-Content D:\home\App_Config\Sitecore.config
  </code></pre>