header image

PowerShell new line

Posted by: | September 9, 2018 Comments Off on PowerShell new line |

A PowerShell new line can be generated using `n. It’s one of a series of special characters recognised by PowerShell.

The full list of Windows PowerShell v5.1 special characters is:

`0 Null
`a Alert
`b Backspace
`f Form feed
`n New line
`r Carriage return
`t Horizontal tab
`v Vertical tab
–% Stop parsing


Here’s some examples:

`0 is a null character – empty space

PS> “abcd`0efg”
abcd efg


`a causes the machine to issue an alert – beep

PS> “`a Beep “; “`a Beep”

Two alerts are sent but you might only hear one.


The backspace character moves the cursor back one space overwriting the character that was there:

PS> “abcd`befg”


Form feed is for printers only


A new line is added by `n

PS> “abc`nde`nfg”


The carriage return returns the cursor to the beginning of the line so any text before it will be overwrittem

PS> “This original text`rIs overwritten by this brand new text”
Is overwritten by this brand new text


A horizontal tab is added by `t

PS> “This`twill`ttab`tacross`tthe`tscreen”
This will tab across the screen


And `v for vertical tabs but only when printing documents – it doesn’t work on screen output


You can use –% to stop interpreting input as PowerShell commands or expressions. In this case PowerShell attempts to evaluate $x

PS> Write-Host $x = a variable
= a variable

but what you really want is

PS> Write-Host –% $x = a variable
–% $x = a variable

Unfortunately, you also get the –% come through.

The about_parsing help file has an example using icacls.


You’ll have noticed that all of the examples were in double quotes – single quotes stop the special character being recognised:

PS> “This`twill`ttab`tacross`tthe`tscreen”
This will tab across the screen
PS> ‘This`twill`ttab`tacross`tthe`tscreen’


PowerShell v6 introduced `u for working with unicode characters

PS> “`u{2195}”

you can have 1 – 6 hex chacraters with a maximim value of 10FFFF

under: PowerShell, PowerShell v5, PowerShell v6

Comments are closed.