Text: Quotes and `$( )`

Double quotes fill in the values of variables and single quotes keep text exactly as typed, $( ) puts a property or a whole command's answer into text, and a here-string holds text of many lines.

Apprentice · PowerShell · Updated

After this lesson you can

  • Choose double quotes to fill in values or single quotes to keep text as typed, and put a quote or a dollar sign inside text
  • Put a property or a command's answer into text with $( ), and write text of many lines with a here-string

Key takeaways

  • Double quotes fill in values: "fix the $machine" becomes fix the kettle-bot. Single quotes keep every character as typed.
  • Text with a dollar sign, such as a price, goes in single quotes, or gets a backtick before the $ inside double quotes.
  • Inside double quotes, $kettle.Length fills in only $kettle. $( ) fills in the whole thing: "$($kettle.Length) bytes".
  • A here-string holds many lines: @" to "@ fills in values, @' to '@ doesn't. The closing mark starts its own line.

The email that says "Hi Sam, your 3 items ship on Friday" wasn't typed by a person. A program took a template and filled in your name, a number and a day. You'll want the same thing in PowerShell all the time: a file name with today's date in it, a line that says how many files a folder has, a note with a few lines to save. The text is the template, the variables are the values, and the kind of quotes you choose decides whether the values get filled in.

This lesson uses the workshop from Variables: $name. If you closed PowerShell since then, run that lesson's practice-folder lines again.

Double quotes fill in, single quotes don't

Text inside quotes is a string, a string of characters. PowerShell has two kinds of quotes, and they behave differently:

$machine = 'kettle-bot'
"Next job: fix the $machine"
'Next job: fix the $machine'
Next job: fix the kettle-bot
Next job: fix the $machine

Double quotes look for $ and fill in the value of each variable they find. Single quotes keep every character exactly as you typed it. Books and other courses call filling in values string interpolation. A good habit: use single quotes unless you want something filled in, so nothing surprises you.

A quote or a dollar sign inside text

Ada's name has an apostrophe, which is the same key as a single quote. In single quotes, the apostrophe ends the text early, the rest of the line stops making sense, and PowerShell shows >> and waits for you to finish. Press Ctrl+C to get your prompt back. Two ways that work:

"Ada's workshop"
'Ada''s workshop'
Ada's workshop
Ada's workshop

Double quotes don't mind an apostrophe, and inside single quotes, two single quotes in a row stand for one.

A dollar sign is the opposite problem. In double quotes, $4 looks like a variable named 4, which is empty, so a price disappears:

"New springs cost $4.50 each"
"New springs cost `$4.50 each"
'New springs cost $4.50 each'
New springs cost .50 each
New springs cost $4.50 each
New springs cost $4.50 each

The backtick `, the key above Tab, means "take the next character as it is". Single quotes are simpler: nothing in them is filled in.

Properties and commands inside text: `$( )`

Double quotes fill in a variable's name, and stop there. A dot after it isn't part of the name, so a property comes out wrong:

$kettle = Get-Item "$HOME\terminal-practice\workshop\kettle-bot.ps1"
"The kettle-bot is $kettle.Length bytes"
"The kettle-bot is $($kettle.Length) bytes"
The kettle-bot is C:\Users\Sam\terminal-practice\workshop\kettle-bot.ps1.Length bytes
The kettle-bot is 67 bytes

The first line filled in the whole file, written as its path, and then wrote .Length after it. $( ) is read "the value of what's inside": PowerShell works out everything in the parentheses first, and puts the answer into the text. It's called a subexpression, and it can hold any command:

$drawings = Get-ChildItem "$HOME\terminal-practice\workshop\projects\clockwork-owl\drawings"
"The owl has $($drawings.Count) drawings"
"owl-backup-$(Get-Date -Format 'yyyy-MM-dd').zip"
The owl has 3 drawings
owl-backup-2026-11-09.zip

Yours shows today's date, and a fourth drawing if you added tail.txt in the last lesson. A file name with the date in it sorts by day, which makes it a favorite for backups. Numbers, Dates and Types has more on dates.

Many lines: here-strings

A note of several lines goes in a here-string: @" at the end of a line, the lines of text, then "@ at the very start of a line of its own. As with ordinary quotes, @" fills in values and @' keeps everything as typed. Paste each block as one piece; PowerShell shows >> until the closing mark arrives.

$note = @"
Dear Ada,
The owl has $($drawings.Count) drawings now.
The kettle-bot still says NO POWER.
"@
Set-Content "$HOME\terminal-practice\workshop\note-for-ada.txt" $note
Get-Content "$HOME\terminal-practice\workshop\note-for-ada.txt"
Dear Ada,
The owl has 3 drawings now.
The kettle-bot still says NO POWER.

A parts order has prices in it, so it goes in a single-quoted here-string, and every $ stays:

$order = @'
Parts to order:
  2 brass springs   $4.50 each
  1 copper beak     $12.00
'@
$order
Parts to order:
  2 brass springs   $4.50 each
  1 copper beak     $12.00

If the closing "@ or '@ has a space in front of it, PowerShell doesn't see it as the end and keeps waiting. Everything here works the same in Windows PowerShell 5.1 and on a Mac or Linux.

Try it. Make a file whose name has today's date in it: New-Item "$HOME\terminal-practice\workshop\notes-$(Get-Date -Format 'yyyy-MM-dd').txt". Then list the workshop folder and find it.

Check yourself

2 questions to try on the lesson page.

So what

Single quotes for text as it is, double quotes when values go in, $( ) for a property or a command, and a here-string for many lines: with those four, PowerShell writes your file names, messages and notes for you.

Key terms

Cheat sheets

Related