As a PowerShell developer, if you are working with quotes, you should know the difference between single and double quotes. In this tutorial, I will explain the difference between single and double quotes in PowerShell.
Single Quotes (') in PowerShell
Single quotes in PowerShell are used to define literal strings. When you enclose a string in single quotes, everything inside the quotes is treated as a literal value. This means that variables and special characters are not interpreted.
Syntax:
'This is a literal string'Double Quotes (") in PowerShell
Double quotes, on the other hand, allow for string interpolation. This means that variables and expressions within the string are evaluated, and their values are inserted into the string.
Syntax:
"This string contains a variable: $variable"Check out PowerShell Variables in Quotes
Difference Between Single and Double Quotes With Examples
Now, let me show you some examples to help you understand the differences between single and double quotes in PowerShell.
Example 1: Literal Strings with Single Quotes
Consider a scenario where you want to print a file path in a script. Using single quotes ensures that the backslashes are treated literally.
$path = 'C:\MyFolder\report.txt'
Write-Output $pathOutput:
C:\MyFolder\report.txtI executed the above PowerShell script using VS code, and you can see the exact output in the screenshot below:

Example 2: Variable Interpolation with Double Quotes
Now, let’s see how double quotes handle variables. Suppose we have a variable that holds a user’s name:
$name = "Alice"
$message = "Hello, $name! Welcome to the PowerShell tutorial."
Write-Output $messageOutput:
Hello, Alice! Welcome to the PowerShell tutorial.In this example, the variable $name is evaluated, and its value is inserted into the string.
Here is the output you can see in the screenshot below:

Check out Add Double Quotes in a String in PowerShell
Example 3: Combine Strings
You can also combine strings using both single and double quotes. This is particularly useful when dealing with complex strings that contain both literal text and variables.
$city = "New York"
$info = 'The city of ' + $city + ' is known for its vibrant culture.'
Write-Output $infoOutput:
The city of New York is known for its vibrant culture.Example 4: Escaping Quotes
Sometimes, you may need to include quotes within your strings. PowerShell provides a way to escape quotes by doubling them.
Single Quotes:
$message = 'It''s a beautiful day in the neighborhood.'
Write-Output $messageOutput:
It's a beautiful day in the neighborhood.Double Quotes:
$quote = "He said, ""Hello, World!"""
Write-Output $quoteOutput:
He said, "Hello, World!"Example 5: Using Quotes in Command Parameters
Quotes can help ensure that spaces and special characters are handled correctly when passing parameters to commands.
$command = "Get-Process -Name 'notepad'"
Invoke-Expression $commandIn this example, single quotes around notepad ensure that the process name is treated as a single argument.
Check out Escape Special Characters in Variables in PowerShell
PowerShell single vs double quotes
Here is a summary of the differences between single and double quotes in PowerShell.
| Feature | Single Quotes (') | Double Quotes (") |
|---|---|---|
| String Literal | Treats everything as literal | Allows variable interpolation |
| Variable Evaluation | Variables are not evaluated | Variables are evaluated and their values inserted |
| Special Characters | Special characters are treated literally | Special characters can be escaped or evaluated |
| Escaping Quotes | Double single quotes to include a single quote | Double double quotes to include a double quote |
| Use Case Example | 'C:\Path\To\File' | "The file path is $path" |
| Command Parameters | Useful for passing exact string values | Useful for combining strings and variables |
Conclusion
I hope you now understand the differences between single and double quotes in PowerShell. Single quotes are ideal for literal strings where you don’t want any interpolation, while double quotes are perfect for strings that include variables and expressions.
Still, do you have any questions? Feel free to leave a comment below.
You may also like the following tutorials:
Bijay Kumar is an esteemed author and the mind behind PowerShellFAQs.com, where he shares his extensive knowledge and expertise in PowerShell, with a particular focus on SharePoint projects. Recognized for his contributions to the tech community, Bijay has been honored with the prestigious Microsoft MVP award. With over 15 years of experience in the software industry, he has a rich professional background, having worked with industry giants such as HP and TCS. His insights and guidance have made him a respected figure in the world of software development and administration. Read more.