Both here documents and strings are using UNIX 0x0A line endings on Windows instead of 0x0D0A. How can I get them to be Windows line endings?
PS C:\> $s = @"
>> now
>> is
>> the
>> "@
PS C:\> $s
now
is
the
PS C:\> $s | Format-Hex
Label: String (System.String) <7B93DCA4>
Offset Bytes Ascii
00 01 02 03 04 05 06 07 08 09 0A 0B 0C 0D 0E 0F
------ ----------------------------------------------- -----
0000000000000000 6E 6F 77 0A 69 73 0A 74 68 65 now�is�the
PS C:\> $s2 = "
>> Now
>> is
>> the
>> "
PS C:\> $s2
Now
is
the
PS C:\> $s2 | Format-Hex
Label: String (System.String) <33E42D9F>
Offset Bytes Ascii
00 01 02 03 04 05 06 07 08 09 0A 0B 0C 0D 0E 0F
------ ----------------------------------------------- -----
0000000000000000 0A 4E 6F 77 0A 69 73 0A 74 68 65 0A �Now�is�the�
PS C:\> $PSVersionTable.PSVersion.ToString()
7.3.7
You have 2 ways of doing this:
You can use dos2unix.
Or you can use a regex.
There are multiple regex syntaxes but for powershell it is just
-replace '(?<!\r)\n', "`r`n"