title: Replace multiline text in a file using Powershell without using Regex
body: <p>I have the following Powershell script:</p>
  
  <pre><code>$oldCode =  @"
              &lt;div id="time_estimate"&gt;
                  &lt;!-- some large table --&gt;
              &lt;/div&gt;
  "@
  
  $newCode = @"
              &lt;div id="time_estimate"&gt;
                                  &lt;!-- nested divs and spans --&gt;
                                  &lt;div id="contact-form"&gt;
  
                                          &lt;?php include "contact-form.php"; ?&gt;
                                  &lt;/div&gt;
                          &lt;/div&gt;
  "@
  
  ls *.html | foreach { 
          $fileContent = [System.Io.File]::ReadAllText($_.FullName)
          $newFileContent = $fileContent.Replace($oldCode, $newCode)
          [System.Io.File]::WriteAllText($_.FullName, $newFileContent)
          Write-Host  "`r`n"
          Write-Host  "Processed - $($_.Name)...`r`n" }
  </code></pre>
  
  <p>This doesn't seem to be replacing the text. Is it an issue with the multiline strings, or the limits of the Replace() method? I would prefer to do the replace without bringing in regex.</p>