Q. What are the differences between single and double quotes in PowerShell?

What are the differences between single and double quotes in PowerShell?

Don Jones

April 29, 2010

1 Min Read
the word powershell on code text background
Alamy

A. There’s only one difference between single and double quotes in PowerShell: Inside double quotes, PowerShell looks for the $ character. If it finds it, it assumes that any following characters, up to the next white space, are a variable name. It replaces the variable reference with the variable’s contents. Consider this:

$a = "Hello"
$b = "$a World"

The $b variable will now contain "Hello World" because $a will be replaced with its contents, “Hello.” Single quotes don’t do this:

$a = 'Hello'
$b = '$a World'

The $b variable now contains "$a World"—the same literal characters we put into it. As a best practice, try to only use double quotation marks when you need this variable-replacement feature; doing so will keep the feature from kicking in when you’re not expecting it.

Sign up for the ITPro Today newsletter
Stay on top of the IT universe with commentary, news analysis, how-to's, and tips delivered to your inbox daily.

You May Also Like