Q. What are the differences between single and double quotes in PowerShell?
April 29, 2010
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.
About the Author
You May Also Like