Home Ask Login Register

Developers Planet

Your answer is one click away!

Matt February 2016

Prevent trailing newline in Powershell Out-File command

How do I prevent Powershell's Out-File command from appending a newline after the text it outputs?

For example, running the following command

"TestTest" | Out-File -encoding ascii test.txt

Produces a file with contents "TestTest\r\n" rather than just "TestTest"


briantist February 2016

In PowerShell 5.0+, you would use:

"TestTest" | Out-File -encoding ascii test.txt -NoNewline

But in earlier versions you simply can't with that cmdlet.

Try this:


Post Status

Asked in February 2016
Viewed 1,654 times
Voted 13
Answered 1 times


Leave an answer

Quote of the day: live life