How to preserve newlines when using variables in here-strings

Question:

When running the following code:

All new lines are removed from the file’s contents, but just running

prints out the file without stripping the new lines.

Any idea how to get it to work as desired using the here-string?

Thanks!

Answer:

Pipe $txt to Out-String inside a sub-expression.

Source:

How to preserve newlines when using variables in here-strings by licensed under CC BY-SA | With most appropriate answer!

Leave a Reply