The PowerShell escape character is the grave-accent(`)
The escape character can be used in three ways:
1) When used at the end of a line, it is a continuation character - so the command will continue on the next line.
2) To indicate that the next character following should be passed without substitution. For example $myVariable will normally be expanded to display the variables contents but `$myVariable will just be passed as $myVariable
3) When used inside quotation marks, the escape character indicates that the following character should be interpreted as a 'special' character.
Special characters
`0 Null `a Alert bell/beep `b Backspace `f Form feed `n New line `r Carriage return `t Horizontal tab `v Vertical tab `' Single quote `" Double quote
These special characters are used to format output on the screen. The default tab stop is 8 spaces.
The escaped quotes allow quotation marks to be displayed on screen, rather than being interpreted as the end of a string.
Examples
PS C:\> Write-Host "First Line `nSecond line First Line Second Line PS C:\> Write-Host "Header1`tHeader2 `nItem1`t123.45 Header1 Header2 Item1 Item2 PS C:\> "`a `a"
Quotation Marks
Either single or double quotes may be used to specify a literal string.
Single-Quoted Strings (')
When you enclose a string in single quotation marks, any variable names in the string such as '$myVar' will appear exacly as typed when the command is processed. Expressions in single-quoted strings are not evaluated (not even escape characters).
$msg = 'Every "lecture" should cost $5000'
Double-Quoted Strings (")
When you enclose a string in double quotation marks, any variable names in the string such as "$myVar" will be
replaced with the variable's value when the
command is processed. You can prevent this substitution by prefixing the $ with an escape character.
$msg = "Every ""lecture"" should cost `$5000"
$msg = "Every 'lecture' should cost `$5000"
$var = 45
"The value of " + '$var' + "is '$var'"
"The value of `$var is '$var'"
$query = "SELECT * FROM Customers WHERE Name LIKE '%JONES%'"
Here-strings
A here-string is a
single-quoted or double-quoted string which can span multiple lines.
Expressions in single-quoted strings are not evaluated.
All the lines in a here-string are interpreted as strings, even though they are not enclosed in quotation marks.
$myHereString = @'
some text with "quotes" and variable names $printthis
some more text
'@
$anotherHereString = @"
The value of `$var is '$var'
some more text
"@
The @ character is also used to create arrays and as a splat operator.
“Be not angry that you cannot make others as you wish them to be, since you cannot make yourself as you wish to be” - Thomas A Kempis
Related:
Pipelines - Pass objects down the pipeline
Variables - Powershell Variables (int, String)