Escape Single Quotes and Double Quotes in PowerShell

Rohan Timalsina Jan 30, 2023 Jul 12, 2022
  1. Use Backticks ` to Escape Double Quotes in PowerShell
  2. Use Double Quotes "" to Escape Single Quotes in PowerShell
Escape Single Quotes and Double Quotes in PowerShell

The single quotes '' and double quotes "" are used to specify a literal string in PowerShell. You can define strings by enclosing them using single or double quotes.

Both quotes help to print the text in PowerShell. But sometimes, you may need to include quote characters in the output.

This tutorial will teach you to escape quotes and make them appear in a string in PowerShell.

Use Backticks ` to Escape Double Quotes in PowerShell

The backtick ` works as the escape characters in PowerShell. You can use them to escape double quotes in a string or script.

The following example includes literal double quotation marks in a string.

"`"Welcome to PowerShell Tutorial`""

Output:

"Welcome to PowerShell Tutorial"

Let’s see another example to escape double quotes and make them appear in the output.

"His name is `"James Bond`"."

Output:

His name is "James Bond".

Use Double Quotes "" to Escape Single Quotes in PowerShell

You can enclose a string in double quotes to escape single quotes in PowerShell.

The following example includes literal single quotation marks in a string.

"'Welcome to PowerShell Tutorial'"

Output:

'Welcome to PowerShell Tutorial'

You can also use single quotes to escape double quotes in PowerShell. This command uses single quotes to escape double quotation marks in a string.

'"Welcome to PowerShell Tutorial"'

Output:

"Welcome to PowerShell Tutorial"

This way, you can easily escape single or double quotes to make them appear in the output. For additional information, see the description about_Quoting_Rules.

Rohan Timalsina avatar Rohan Timalsina avatar

Rohan is a learner, problem solver, and web developer. He loves to write and share his understanding.

LinkedIn Website

Related Article - PowerShell String