---
title: "Escape Double Quotes in PowerShell: Multiple Methods"
description: "Discover various methods to escape double quotes in PowerShell, making your scripts more robust and reliable."
canonical: "https://adamtheautomator.com/powershell-escape-double-quotes/"
---

# Escape Double Quotes in PowerShell: Multiple Methods

> Discover various methods to escape double quotes in PowerShell, making your scripts more robust and reliable.

Source: https://adamtheautomator.com/powershell-escape-double-quotes/

---

ATA Learning

Tap to hide

[

ATA Learning

](/)

*   [Home](/)
*   [Tutorials](/tutorials/)
*   [Instructors](/author/)
*   [Advertising](/advertising/)
*   [Recommended Resources](/resources/)
*   [About Adam](/about-adam/)

Search for:  

*   [](https://twitter.com/adbertram)
*   [](https://github.com/Adam-the-Automator)
*   [](https://www.linkedin.com/company/adam-the-automator-llc)
*   [](/feed/)

![Escape Double Quotes in PowerShell: Multiple Methods](https://adamtheautomator.com/wp-content/uploads/2019/07/photo-1490019978860-0a20d81982b5.jpg)

# Escape Double Quotes in PowerShell: Multiple Methods

[![](https://secure.gravatar.com/avatar/4147968aa2332aa682bcebf295e4e9d0eb2672dee3d9ae0523a00ac51e7d6017?s=192&d=mm&r=g)Bill Kindle](https://adamtheautomator.com/author/bill/)25 July 20194 min. read

Categories: [IT Ops](/category/it-ops/)

Tags:[PowerShell](/tag/powershell/)

Table of Contents

*   [‘Single Quotes’](#-single-quotes-)
*   [“Double Quotes”](#double-quotes)
*   [Real World Scenario](#real-world-scenario)
*   [Using PowerShell to Escape Double Quotes](#escaping-double-quotes)
*   [Summary](#summary)
*   [Additional Resources](#additional-resources)

There are two types of quotes that can be used in PowerShell: single and double-quotes. In this article, you’re going to learn a bit about quotes and how to use PowerShell to escape double quotes.

Some critical differences between the two can make or break a script. Knowing these differences will make you a more effective PowerShell scriptwriter and help you avoid a rather simple mistake.

In this post, you will learn these differences and see examples of each scenario.

## ‘Single Quotes’

Single quotation strings are what you will most often use and encounter when [creating or troubleshooting PowerShell](https://adamtheautomator.com/teams-webhooks/) scripts.

Consider the following example:

```powershell
# Assign a variable with a literal value of 'single'.
$MyVar1 = 'single'

# Put the variable into another literal string value.
Write-Host -Message 'Fun with $MyVar1 quotes.'
```

Now examine the output:

![Literal string behavior in PowerShell](/wp-content/uploads/2019/07/single-literal-2.png)

Literal string behavior in PowerShell

In the above case, PowerShell ignores `$MyVar1` and treats the variable _literally_ as `$MyVar1`, exactly what was typed. There is no substitution here.

But how do you get PowerShell to recognize the variable value within a quoted string value? That’s where double quotation comes in.

## “Double Quotes”

Double quotes gives you a _dynamic_ element to string values. You will encounter this type of string quotation when the string contains dynamic data from variables stored in memory or dynamically generated.

Consider the following example:

```powershell
# Same as previous example. Create a variable with a simple value.
$MyVar2 = 'double'

# Now to demonstrate double quotes magical power of interpretation!
Write-Host -Message "Fun with $MyVar2 quotes."
```

Now examine the output:

![Variable expansion in PowerShell](/wp-content/uploads/2019/07/double-dynamic.png)

Variable expansion in PowerShell

In the above case, PowerShell processes `$MyVar2` because it was enclosed by a double-quoted string. Double quotes make PowerShell parse for text (the variable) preceded by a dollar sign and substitutes the variable name the corresponding value.

## Real World Scenario

Now, apply this knowledge to a real scenario. Let’s say that you need to create a small function that will give an operator on your team some real basic information:

*   Date / Time
*   Disk % Used
*   Disk % free

You need to return this information visually to an operator. Simple.

First, some pseudo code. We need to display the date time as today’s date and time. Think about how this string value will work. We can use `Get-Date` cmdlet and the `Uformat` parameter to give us the required date/time by using the correct patterns:

```powershell
$date = Get-Date -UFormat "%m / %d / %Y:"
```

Testing the code in a PowerShell terminal confirms this works:

![Date formatting in PowerShell](/wp-content/uploads/2019/07/date-format.png)

Date formatting in PowerShell

That takes care of the first part of the script. Now, I need to gather some disk information to also output to the terminal. The key metric I’m looking for is the percentage of free space remaining. I’ll display this information using `Write-Host` again, but this time I’ll need to insert additional code inside the double-quoted string.

Remember, this information will be dynamic. For the purposes of this example, I’m going to create a variable, then utilize an available member type property to get the value I’m looking for:

```powershell
$disk = Get-DiskSpace | Where-Object -Property Name -EQ 'C:\'
```

Testing the code in a PowerShell terminal confirms this works:

![Referencing object properties ](/wp-content/uploads/2019/07/percent-free.png)

Referencing object properties

Perfect. We now have two variables that we can place in the strings that the operator will see when running this function. So let’s assemble the bits into the final script that will become our function:

```powershell
function Get-CurrentDiskPercentageUsed {
    $date = Get-Date -UFormat "%m / %d / %Y:"
    $disk = Get-DiskSpace | Where-Object -Property Name -EQ 'C:\'         
    Write-Host "Storage report for $date"
    Write-Host -ForegroundColor Yellow "There is $($disk.PercentFree)% total disk space remaining."
}
```

Testing again in a PowerShell terminal, here is what the operator would see:

![Bringing code together in a PowerShell function](/wp-content/uploads/2019/07/final-output.png)

Bringing code together in a [PowerShell function](https://adamtheautomator.com/powershell-functions/ "PowerShell function")

Notice what I did inside the last `Write-Host` line with the `$disk` variable. PowerShell evaluates the `$( )` subexpression operator as an entire subexpression then replaces the result. Doing it this way also helps you avoid having to create more variables, which saves memory and can even make your script faster.

The function still needs some work. So let’s finish it off by adding some math to show a full calculation to the operator:

```powershell
function Get-CurrentDiskPercentageUsed {
    $date = Get-Date -UFormat "%m / %d / %Y:"
    $disk = Get-DiskSpace | Where-Object -Property Name -EQ 'C:\'
    Write-Host "Storage report for $date"
    Write-Host -ForegroundColor Red "There is $(100 - $disk.PercentFree)% total disk utilization on drive $($disk.Name)."
    Write-Host -ForegroundColor Yellow "There is $($disk.PercentFree)% total disk space remaining."
 }
```

Results:

![Adding math calculation to example script](/wp-content/uploads/2019/07/simple-math.png)

Adding math calculation to example script

The operator can now make some faster decisions while supporting a remote system by using this function.

## Using PowerShell to Escape Double Quotes

Now that you know all about how single and double quotes work in PowerShell, let’s cover a more advanced topic; escaping double quotes in strings.

Since you now know that double quotes expand variables inside of strings, what happens when you need to include literal double quotes _inside_ of a string? In that case, you need to _escape_ them or use single quotes.

> _Escaping_ is a term that refers to refers to making making non-literal elements literal. It’ll be much easier to understand with an example below.

Let’s say you need to create a string with double quotes inside of it like below. Notice that, as is, `"string"` doesn’t actually include the double quotes.

```powershell
PS51> "string"
string
```

To include the double quotes inside of the string, you have two options. You can either enclose your string in single quotes or escape the double quotes with a symbol called a backtick. You can see an example of both below of using PowerShell to escape double quotes.

Notice that `"string"` now includes the double quotes.

```powershell
PS51> '"string"'
"string"
PS51> "`"string`""
"string"
```

## Summary

There’s not much to quotes in PowerShell. The one key concept to remember is that you need to know when to be _literal_ `' '` , and when to be _dynamic_ `" "`. By default, you should always use single quotes unless there is a requirement for dynamic data in the string construct.

## Additional Resources

To learn more about quotation rules, visit the [about\_Quoting\_Rules](https://docs.microsoft.com/en-us/powershell/module/microsoft.powershell.core/about/about_quoting_rules?view=powershell-6) PowerShell documentation from Microsoft or [this excellent MSDN article](https://blogs.msdn.microsoft.com/koryt/2018/03/01/powershell-for-programmers-strings-quotes-and-quirks/). For even more examples of single/double quote usage, read Kevin Marquette’s “[Everything you wanted to know about variable substitution in strings](https://powershellexplained.com/2017-01-13-powershell-variable-substitution-in-strings/)” .

You can also check out many of the other blog posts here on Adam the Automator on strings:

*   [The PowerShell Substring: Finding a string inside a string](https://adamtheautomator.com/powershell-substring/)
*   [Learn the PowerShell string format and expanding strings](https://adamtheautomator.com/powershell-string-format/)
*   [PowerShell Variables in Strings](https://adamtheautomator.com/powershell-variable-in-strings/)

Share this article

[Share on X](https://twitter.com/intent/tweet?url=https%3A%2F%2Fadamtheautomator.com%2Fpowershell-escape-double-quotes%2F&text=Escape%20Double%20Quotes%20in%20PowerShell%3A%20Multiple%20Methods)[Share on Facebook](https://www.facebook.com/sharer/sharer.php?u=https%3A%2F%2Fadamtheautomator.com%2Fpowershell-escape-double-quotes%2F)[Share on LinkedIn](https://www.linkedin.com/sharing/share-offsite/?url=https%3A%2F%2Fadamtheautomator.com%2Fpowershell-escape-double-quotes%2F)

## Related Posts

![](https://adamtheautomator.com/wp-content/uploads/2026/06/26995-troubleshoot-dns-issues-powershell-codex.webp)

### [Troubleshoot DNS Issues with PowerShell](/troubleshoot-dns-issues-powershell/)

Troubleshoot DNS issues with PowerShell by testing name resolution, DNS client settings, cache entries, and network connectivity in a repeatable workflow.

![](https://adamtheautomator.com/wp-content/uploads/2025/10/image_2025-10-24_095322075.png)

### [Migrating from PowerShell 6 to 7.5: Breaking Changes/New Features](/migrating-powershell-6-to-7-5/)

Migrate from PowerShell Core 6 to 7.5: breaking changes, features, and testing tips.

![](https://adamtheautomator.com/wp-content/uploads/2025/06/featured-image-6.png)

### [How to Add Timeouts to Pester Tests with PowerShell Runspaces](/pester-test-timeout-runspaces/)

Prevent Pester tests from hanging indefinitely using PowerShell runspaces. Learn to handle variable scoping, module loading, TestDrive access, and stream capture challenges with timeout protection.

## Categories

*   [IT Ops](/category/it-ops/)
*   [Cloud](/category/cloud/)
*   [DevOps](/category/devops/)
*   [Home Ops](/category/home-ops/)
*   [Information Security](/category/infosec/)
*   [Software Development](/category/software-development/)

## Site

*   [Home](/)
*   [Tutorials](/tutorials/)
*   [Instructors](/author/)
*   [Advertising](/advertising/)
*   [Recommended Resources](/resources/)
*   [About Adam](/about-adam/)

Copyright 2026© ATA Learning | [Privacy Policy](/privacy/)
