PowerTip: New Lines with PowerShell


Summary: Create new lines with Windows PowerShell.

Hey, Scripting Guy! Question How can I use Windows PowerShell to add a new line between lines for my text output?

Hey, Scripting Guy! Answer Use the `n character, for example:

PS C:\> "string with new line `n in it"

string with new line

 in it

Note  If you need a carriage return, use `r. For a carriage return and a new line, use `r`n.

Comments (4)

  1. Thanks you The Scripting Guys..

  2. sandeep says:

    PS C:chelsioautofwwin_sandeep> $rt = 1,2,3,4
    PS C:chelsioautofwwin_sandeep> $rt
    1
    2
    3
    4
    PS C:chelsioautofwwin_sandeep> $rt = $rt -join ‘n’
    PS C:chelsioautofwwin_sandeep> $rt
    1n2n3n4

    i wanted to format my output, line by line but when we printed i still see the newline characters..!,
    how do i get rid of displaying new-character on console..?

  3. Bram says:

    @sandeep: Use double quotes instead of single. Also use the backtick (`) as escape char instead of the backslash ()
    $rt = $rt -join "`n"

  4. Bram says:

    When would you need a carriage return? Is `n not always enough?

Skip to main content