PowerShell for Windows Admins

Sep 13 2018   9:43AM GMT

PowerShell new line

Richard Siddaway Richard Siddaway Profile: Richard Siddaway

Tags:
Powershell

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”
Beep
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”
abcefg

Form feed is for printers only

A new line is added by `n

PS> “abc`nde`nfg”
abc
de
fg

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

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 recognized:

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

PowerShell v6 introduced `u for working with unicode characters
PS> “`u{2195}”

You can have 1 – 6 hex characters with a maximum value of 10FFFF

 Comment on this Post

 
There was an error processing your information. Please try again later.
Thanks. We'll let you know when a new response is added.
Send me notifications when other members comment.

Forgot Password

No problem! Submit your e-mail address below. We'll send you an e-mail containing your password.

Your password has been sent to:

Share this item with your network: