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?

link|improve this question

68% accept rate
It also adds a byte order mark (EFBBBF). – Andrew J. Brehm Feb 10 '11 at 16:00
feedback

1 Answer

Here is a workaround from this site.

Use

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

Your Answer

 
or
required, but never shown

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