title: Insert Content into Text File in Powershell
body: <p>I want to add content into the middle of a text file in Powershell.  I'm searching for a specific pattern, then adding the content after it.  Note this is in the middle of the file.</p>
  
  <p>What I have currently is:</p>
  
  <pre><code> (Get-Content ( $fileName )) | 
        Foreach-Object { 
             if($_ -match "pattern")
             {
                  #Add Lines after the selected pattern
                  $_ += "`nText To Add"
             }
        }
    } | Set-Content( $fileName )
  </code></pre>
  
  <p>However, this doesn't work.  I'm assuming because $_ is immutable, or because the += operator doesn't modify it correctly?</p>
  
  <p>What's the way to append text to $_ that will be reflected in the following Set-Content call?</p>