Server Fault is a question and answer site for system and network administrators. It's 100% free, no registration required.

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

When I read a file into a variable

$file = Get-Content myfile.utf8

and then write this same content into a new file

Set-Content -Encoding utf8 mynewfile.txt $file

Powershell automatically adds a return and linefeed to the end of the file.

How can I get the content of a file and write it back without Powershell adding anything?

share|improve this question
It also adds a byte order mark (EFBBBF). – Andrew J. Brehm Feb 10 '11 at 16:00

Here is a workaround from this site.


[System.IO.File]::WriteAllText($path, $text)
share|improve this answer
For me that doesn't write anything to anything. – Andrew J. Brehm Feb 11 '11 at 16:01

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.