liveBook · Manning

Quotation marks

As explained in Learn PowerShell in a Month of Lunches: Fourth Edition, Covers Windows, Linux, and macOS

A double quotation mark delimits a PowerShell expandable string in which variable references can be replaced by their values.

Double quotation marks create expandable strings: PowerShell replaces variable references with their values when it first parses the string. Single quotation marks keep those references literal. section 16.3 section 26.1.2

Build a message from a variable

Set $computername to 'SRV-02', then assign "The computer name is $computername" to $phrase. PowerShell displays “The computer name is SRV-02”. Changing $computername later does not update $phrase, because replacement happened when the string was parsed. section 16.3

Use double quotation marks for these practical string-building tasks:

  • Escape a dollar sign with the backtick so it remains visible instead of starting variable replacement. section 16.3
  • Insert a command result with a subexpression such as $($processes[0].name); PowerShell evaluates the expression and places its result in the string. section 16.5
  • Represent special characters such as a newline or tab with backtick sequences including `n and `t. section 16.3 section 26.2.3
PS > $computername = 'SRV-02'
PS > $phrase = "The computer name is $computername"
PS > $phrase
The computer name is SRV-02

See variable interpolation produce a complete sentence, then compare it with the literal single-quoted form in b1 and the escaped form in b4. section 16.3

How Learn PowerShell in a Month of Lunches: Fourth Edition, Covers Windows, Linux, and macOS covers it

How deep it goes
Explains interpolation, parse-time behavior, escaping, subexpressions, and delimiters through runnable examples without covering broader parsing internals.
Examples
Demonstrates computer-name messages, process names, customized prompts, escaped dollar signs, newlines, tabs, and pipe-delimited arrays.
What it assumes
Assumes basic PowerShell variables and strings while distinguishing single-quoted literals from expandable double-quoted strings.
What you can do after
Apply it via PowerShell to construct dynamic strings, embed command results, escape characters, and split or join delimited data.
How it connects
Connects expandable strings with variables, escape characters, subexpressions, arrays, -join, and -split.

Related concepts

This explainer was generated by Manning's knowledge graph from the text of Learn PowerShell in a Month of Lunches: Fourth Edition, Covers Windows, Linux, and macOS. The section links point to the parts of the book it draws on.