title: Powershell - Streamwriter
body: <p>I need to write to many files as quickly as possible but I'm not getting the results I want using Streamwriter the way I'm using. For example, if I write...</p>
  
  <pre><code>$File = "c:\somefile"
  $Contents = get-content $File
  $Contents | set-content $File
  </code></pre>
  
  <p>So read the contents of the file, do nothing, and write it back... The file is exactly the same. However if I write...</p>
  
  <pre><code>$File = "c:\somefile"
  $Contents = get-content $File
  $stream = [System.IO.StreamWriter] $File
  $stream.WriteLine("$contents")
  $stream.close()
  </code></pre>
  
  <p>Then the file looks as though all line breaks have been ignored and is a bit of a mess. What do I need to do to get it write properly? Many thanks! </p>