Recently, I was working on a PowerShell script that needed to handle financial data with dollar amounts. What seemed like a straightforward task quickly became frustrating when my script kept interpreting the dollar signs as variable indicators instead of literal characters.
If you’ve ever encountered this issue, you know how perplexing it can be. PowerShell treats the dollar sign ($) as a special character that indicates a variable, which means you can’t just include it in a string without taking precautions.
In this article, I will show five reliable methods to escape dollar signs in PowerShell based on my decade of experience. Let’s dive in!
Why Do We Need to Escape Dollar Signs in PowerShell?
In PowerShell, the dollar sign ($) is a special character used to denote variables. When PowerShell encounters a $ followed by a name in a double-quoted string, it attempts to replace it with the value of the variable with that name.
For example, if you write:
$name = "John"
"Hello $name"
PowerShell outputs: Hello John
But what if you actually want to include a dollar sign in your output, such as when working with currency? That’s where escaping comes in.
Here are a few methods you can use:
Method 1 – Using the Backtick (`) Character
The most common way to escape special characters in PowerShell is by using the backtick (`) character.
Here is an example.
$text = "The item costs `$25.99"
Write-Output $text
This will output: The item costs $25.99
You can see the exact output in the screenshot below:

The backtick tells PowerShell to treat the following character literally, rather than interpreting it as a special character. This works well when you need to escape a dollar sign within double-quoted strings in PowerShell.
Method 2 – Using Single Quotes
Another simple approach is to use single quotes instead of double quotes. PowerShell treats everything inside single quotes as literal text, with no variable expansion.
$text = 'The item costs $25.99'
Write-Output $text
Output: The item costs $25.99
Here is the exact output: I executed the above PowerShell script using VS Code. Follow the screenshot below:

This method is straightforward but has a limitation – you can’t include variables within single-quoted strings. If you need to combine literal dollar signs with variable values, you’ll need a different approach.
Check out Replace String Containing Special Characters in PowerShell
Method 3 – Using the -f Operator (Format Operator)
The format operator is a powerful way to construct strings with both variables and literal dollar signs:
$price = 25.99
$text = "The item costs {0}" -f ('$' + $price)
Write-Output $text
Output: The item costs $25.99
In this example, we use {0}$ to include a literal dollar sign, followed by {1} which gets replaced with the value of $price. The empty string passed as the first argument is a placeholder for {0}.
Here is the exact output in the screenshot below:

Check out Replace String Containing Double Quotes in PowerShell
Method 4 – Using the [char] Type Accelerator
You can also represent the dollar sign using its ASCII or Unicode value:
$dollarSign = [char]36 # ASCII value for $
$text = "The item costs " + $dollarSign + "25.99"
Write-Output $text
Output: The item costs $25.99
This method is a bit more verbose but can be useful in certain scripting scenarios where other approaches might not work.
You can see the output in the screenshot below:

Read PowerShell Replace String Case Insensitive
Method 5 – Using Here-Strings for Multiline Text
When working with multiline text that contains dollar signs, PowerShell’s here-strings can be extremely useful:
$text = @"
Invoice Details:
Product A: `$15.99
Product B: `$24.99
Total: `$40.98
"@
Write-Output $text
Output:
Invoice Details:
Product A: $15.99
Product B: $24.99
Total: $40.98
Notice that I still needed to use the backtick to escape the dollar signs because I’m using the @"..."@ format (which performs variable expansion like double quotes). If I used the @'...'@ format (with single quotes), I wouldn’t need to escape the dollar signs at all.
Handling Special Cases: Replacing Strings with Dollar Signs
When you need to replace strings containing special characters like dollar signs, you need to be extra careful:
$text = "The price is $25.99 but we offer a 10% discount."
$oldString = "$25.99"
$newString = "$19.99"
# This won't work as expected
$result = $text -replace $oldString, $newString
# This will work - escape the $ in the pattern
$result = $text -replace "\$25\.99", "$19.99"
Write-Output $result
Output: The price is $19.99 but we offer a 10% discount.
Notice that I had to:
- Escape the dollar sign with a backslash
- Escape the period with a backslash (since periods are also special characters in regex patterns)
Real-World Example: Processing Financial Data
Let’s look at a practical example of processing financial data where escaping dollar signs becomes crucial:
# Sample CSV data with dollar amounts
$csvData = @"
Product,Price,Discount
Laptop,`$999.99,10%
Monitor,`$299.99,5%
Keyboard,`$79.99,0%
"@
# Save to a temporary file
$csvPath = "$env:TEMP\products.csv"
$csvData | Out-File -FilePath $csvPath
# Read and process the CSV
$products = Import-Csv -Path $csvPath
# Calculate discounted prices and remove the $ symbol
foreach ($product in $products) {
$price = [decimal]($product.Price -replace '\$', '')
$discount = [decimal]($product.Discount -replace '%', '') / 100
$discountedPrice = $price * (1 - $discount)
Write-Output "Product: $($product.Product)"
Write-Output "Original Price: `$$price"
Write-Output "Discount: $($product.Discount)"
Write-Output "Final Price: `$$($discountedPrice.ToString('F2'))"
Write-Output "------------------------"
}
# Clean up
Remove-Item -Path $csvPath
This script demonstrates how to:
- Create CSV data with escaped dollar signs
- Parse the data and remove the dollar signs when needed for calculations
- Add dollar signs back when displaying the final results
Best Practices for Handling Dollar Signs in PowerShell
Based on my years of experience with PowerShell, here are some best practices to follow:
- Use single quotes when possible – If you don’t need variable expansion, single quotes are the simplest option.
- Be consistent with your approach – Stick to one method throughout your script to maintain readability.
- Consider string formatting for complex cases – The
-foperator gives you more control over string composition. - Comment your code – When using escaped characters, add comments to clarify your intentions.
- Test thoroughly – Always test your scripts with various inputs to ensure dollar signs are handled correctly.
In this tutorial, I have explained how to escape the dollar sign in PowerShell using five methods:
- Using the Backtick (`) Character
- Using Single Quotes
- Using the -f Operator (Format Operator)
- Using the [char] Type Accelerator
- Using Here-Strings for Multiline Text
I hope you found this guide helpful. If you have any questions or run into specific issues with dollar signs in your PowerShell scripts, feel free to ask in the comments below!
Other PowerShell articles you may also like:
- Replace Strings Containing Backslashes in PowerShell
- Replace Carriage Returns in Strings Using PowerShell
- Replace a String in Text File with PowerShell
- PowerShell Replace String Before Character

Hey! I’m Bijay Kumar, founder of SPGuides.com and a Microsoft Business Applications MVP (Power Automate, Power Apps). I launched this site in 2020 because I truly enjoy working with SharePoint, Power Platform, and SharePoint Framework (SPFx), and wanted to share that passion through step-by-step tutorials, guides, and training videos. My mission is to help you learn these technologies so you can utilize SharePoint, enhance productivity, and potentially build business solutions along the way.