silverspr
silverspr

Reputation: 25

Powershell piped out-file -append adding additonal CRLF between lines

this is probably very simple but I've not been able to get this working. Using either of these two very 'simple' scripts:

get-date >> C:\list3.txt OR

(get-date).Date | Out-String -FilePath C:\list3.txt -Append

produces a text file with too many leading and trailing CRLF

CRLF
April 25, 2020 00:00:00 CRLF
CRLF
CRLF
CRLF
April 25, 2020 00:00:00 CRLF
CRLF
CRLF
CRLF

Behaves this way in either Notepad or Notepad++

What do I need to fix to have only one CRLF per line
April 25, 2020 00:00:00 CRLF
April 25, 2020 00:00:00 CRLF

thanks in advance

Upvotes: 0

Views: 348

Answers (1)

js2010
js2010

Reputation: 27453

I would use set-content or add-content. It doesn't add extra formatting. Plus out-file -append can mix encodings (utf8, utf16) in the same file.

get-date | Add-Content file
get-date | Add-Content file
get-date | Add-Content file
cat file

4/25/2020 4:57:22 PM
4/25/2020 4:57:24 PM
4/25/2020 4:57:24 PM

Upvotes: 1

Related Questions