title: keeping default encoding type upon writing lines
body: <p>I am using the following script to delete the last line of a file, the problem is that it seems to be changing the encoding type of the file to something else which makes characters such pound (£) signs unreadable.</p>
  
  <pre><code>$path = "D:\Test\"
  $filter =  "*.txt"
  $files = Get-ChildItem -path $path -filter $filter
  
  foreach ($item in $files) {
      Write-Host "Start Processing "  $item.FullName -foregroundcolor "green"
  
      # Read all lines
      $LinesInFile = [System.IO.File]::ReadAllLines($item.FullName)
      # Write all lines, except for the last one, back to the file
      [System.IO.File]::WriteAllLines($item.FullName,$LinesInFile[0..($LinesInFile.Count - 2)])
      # Clean up
      Remove-Variable -Name LinesInFile
  
      Write-Host "Ended Processing "  $item.FullName -foregroundcolor "white"
  }
  </code></pre>
  
  <p>I tried setting the encoding type upon writing files to "ANSI" which seems to be the default encoding type of the files, however, nothing happens.  </p>
  
  <blockquote>
    <p>Encoding.GetEncoding(1252)</p>
  </blockquote>
  
  <pre><code>[System.IO.File]::WriteAllLines($item.FullName,$LinesInFile[0..($LinesInFile.Count - 2)],  Encoding.GetEncoding(1252))
  </code></pre>