How to Add a New Line in a PowerShell String

To add a new line in a PowerShell string, put `n (backtick n) inside a double-quoted string. The text after it starts on the next line:

$message = "Order 1042 has shipped.`nIt should arrive by Friday, October 2, 2026."
$message

Output:

Order 1042 has shipped.
It should arrive by Friday, October 2, 2026.
PowerShell new line in a string with backtick n
A backtick n splits the string over two lines (PowerShell 7)

That covers most scripts. Below I show the other new line options, when each one matters, and how to turn spaces into new lines.

I ran every example in PowerShell 7.6 and Windows PowerShell 5.1, and the results were identical.

`n vs `r`n vs [Environment]::NewLine

PowerShell has three common ways to write a line break. This shows the actual characters each one produces on Windows:

function Show-Breaks([string]$Text) { $Text.Replace("`r", '\r').Replace("`n", '\n') }

'Backtick n:           ' + (Show-Breaks "A`nB")
'Backtick r n:         ' + (Show-Breaks "A`r`nB")
'Environment NewLine:  ' + (Show-Breaks "A$([Environment]::NewLine)B")

Output:

Backtick n:           A\nB
Backtick r n:         A\r\nB
Environment NewLine:  A\r\nB
SyntaxCharactersUse it for
`nLine feed (LF)Console output and most strings
`r`nCarriage return + line feed (CRLF)Windows text files and tools that expect CRLF
[Environment]::NewLineCRLF on Windows, LF on Linux and macOSScripts that run on more than one OS

In the console, `n and `r`n look the same. The difference only shows up in files and in programs that read them.

Why `n doesn’t work in single quotes

Backtick escapes only work in double-quoted strings. Single quotes print everything exactly as typed:

'Single quotes: Line one`nLine two'
"Double quotes: Line one`nLine two"

Output:

Single quotes: Line one`nLine two
Double quotes: Line one
Line two

If your `n shows up as literal text, check the quotes first.

Use [Environment]::NewLine for cross-platform scripts

[Environment]::NewLine returns the line break of the OS the script runs on. It’s handy when you build a string by adding parts together:

$address = '1600 Pennsylvania Ave NW' + [Environment]::NewLine + 'Washington, DC 20500'
$address

Output:

1600 Pennsylvania Ave NW
Washington, DC 20500

PowerShell 7 runs on Linux and macOS too, so this keeps your output right everywhere without checking the OS yourself.

Write multi-line text with a here-string

For longer text, like an email body, a here-string is easier to read than a string full of `n. Everything between @" and "@ keeps its line breaks, and variables still expand:

$name  = 'Alice'
$total = 149

$body = @"
Hi $name,

Your order total is `$$total.
Thanks for shopping with us.
"@

$body

Output:

Hi Alice,

Your order total is $149.
Thanks for shopping with us.

The closing "@ must start at the beginning of its own line. Use @' and '@ instead when you don’t want variables to expand. about_Quoting_Rules covers both forms.

One thing to know: a here-string gets its line breaks from the script file itself. I saved the same script with CRLF and LF endings, and the here-string had CRLF in one and LF in the other.

Join lines into one string