Take the 2-minute tour ×
Server Fault is a question and answer site for system and network administrators. It's 100% free, no registration required.

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

1 Answer 1

Here is a workaround from this site.

Use

[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

 
discard

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.