Don’t do that #19: Use double quotes to escape characters

By | April 12, 2015

Don’t do that: You want to display: The share \\server\share$ is not available (where share$ is a hidden share).

You write the following code and you escape the double quotes with a backtick (`), the double quotes are missing:

Output:

double quotes escape powershell

So you do the following and it works:

sinle quotes powershell escape


Do that: A better way is to use just the single quotes instead of double quotes:

Write-Output -InputObject 'The share "\\server\share$" is not available'

Output:

write-output-single-quotes

Note: single quotes don’t allow variable expansion (in other words, variables between single quotes are not interpreted).


previous-buttonNext button blue

Leave a Reply

Your email address will not be published. Required fields are marked *