tl;dr

Inside "...":

  • $(...) is only needed to embed entire expressions or commands (e.g. "PSVersionTable.PSVersion)")

  • ${...} is only needed if a stand-alone reference to a variable with a non-special name needs delimiting (disambiguation), so that subsequent characters in the string aren't interpreted as part of the variable name (e.g, "${foo}_bar" correctly embeds variable $foo; without {...}, PowerShell would look for variable $foo_bar; notably, a subsequent : requires this technique too: "${foo}:bar"; by contrast, something like "$foo!" also works without {...})

Independently of use in "...", ${...} is also needed for variable names containing special characters (e.g. ${a-b} = 42)

For a comprehensive overview of PowerShell's expandable strings (string interpolation), see this answer.


Background information:

To complement marsze's helpful answer:

${...} (enclosing the variable name in { and }) is indeed always necessary if a variable name contains special characters, such as spaces, . or -.

  • Not special are _ and - surprisingly and problematically - ?.

    • For the exact rules, see the relevant section of the conceptual "about_Variables" help topic, Variable Names that Include Special Characters.
  • (The first occurrence of) : in a name is invariably interpreted as terminating either a PowerShell drive reference - in the context of namespace variable notation - or a scope specifier, irrespective of whether {...} enclosure is used or required (e.g., in $env:USERNAME or ${env:USERNAME}, env refers to the Env: PowerShell drive representing all environment variables; in $script:foo or ${script:foo}, script refers to the script's scope and its variables).

Note:

  • ${...} - the syntax for disambiguating a variable name - is not to be confused with $(...), the subexpression operator, which is needed to embed any expression or command that goes beyond a stand-alone variable reference inside "...", an expandable (interpolating) string.

  • As such, these two syntax forms are independent of one another and may need to be combined in a given situation; e.g. "$var" / "${var}" work fine, but "$var.someProperty" / "${var}.someProperty" do not: you need "var.someProperty)" / "{var}.someProperty)"

In the context of "...", there is another reason to use ${...}, even if the variable name itself doesn't need it:

If you need to delineate the variable name from directly following non-whitespace characters, notably including ::

$foo = 'bar'  # example variable

# INCORRECT: PowerShell assumes that the variable name is 'foobarian', not 'foo'
PS> "A $foobarian."
A .  # Variable $foobarian doesn't exist -> reference expanded to empty string.

# CORRECT: Use {...} to delineate the variable name:
PS> "A ${foo}barian."
A barbarian.

# INCORRECT: PowerShell assumes that 'foo:' is a *namespace* (drive) reference
#            (such as 'env:' in $env:PATH) and FAILS:
PS> "$foo: bar"
Variable reference is not valid. ':' was not followed by a valid variable name character. 
Consider using ${} to delimit the name.

# CORRECT: Use {...} to delineate the variable name:
PS> "${foo}: bar"
bar: bar

See this answer for a comprehensive overview of PowerShell string-expansion rules.

Note that you need the same technique when string expansion is implicitly applied, in the context of passing an unquoted argument to a command; e.g.:

# INCORRECT: The argument is treated as if it were enclosed in "...",
#            so the same rules apply.
Write-Output $foo:/bar

# CORRECT
Write-Output ${foo}:/bar

Finally, a somewhat obscure alternative is to `-escape the first character after the variable name, but the problem is that this only works as expected with characters that aren't part of escape sequences (see about_Special_Characters):

# OK: because `: is not an escape sequence.
PS> "$foo`: bar"
bar: bar

# NOT OK, because `b is the escape sequence for a backspace character.
PS> "$foo`bar"
baar # The `b "ate" the trailing 'r' of the variable value
     # and only "ar" was the literal part.
Answer from mklement0 on Stack Overflow
Top answer
1 of 3
200

tl;dr

Inside "...":

  • $(...) is only needed to embed entire expressions or commands (e.g. "PSVersionTable.PSVersion)")

  • ${...} is only needed if a stand-alone reference to a variable with a non-special name needs delimiting (disambiguation), so that subsequent characters in the string aren't interpreted as part of the variable name (e.g, "${foo}_bar" correctly embeds variable $foo; without {...}, PowerShell would look for variable $foo_bar; notably, a subsequent : requires this technique too: "${foo}:bar"; by contrast, something like "$foo!" also works without {...})

Independently of use in "...", ${...} is also needed for variable names containing special characters (e.g. ${a-b} = 42)

For a comprehensive overview of PowerShell's expandable strings (string interpolation), see this answer.


Background information:

To complement marsze's helpful answer:

${...} (enclosing the variable name in { and }) is indeed always necessary if a variable name contains special characters, such as spaces, . or -.

  • Not special are _ and - surprisingly and problematically - ?.

    • For the exact rules, see the relevant section of the conceptual "about_Variables" help topic, Variable Names that Include Special Characters.
  • (The first occurrence of) : in a name is invariably interpreted as terminating either a PowerShell drive reference - in the context of namespace variable notation - or a scope specifier, irrespective of whether {...} enclosure is used or required (e.g., in $env:USERNAME or ${env:USERNAME}, env refers to the Env: PowerShell drive representing all environment variables; in $script:foo or ${script:foo}, script refers to the script's scope and its variables).

Note:

  • ${...} - the syntax for disambiguating a variable name - is not to be confused with $(...), the subexpression operator, which is needed to embed any expression or command that goes beyond a stand-alone variable reference inside "...", an expandable (interpolating) string.

  • As such, these two syntax forms are independent of one another and may need to be combined in a given situation; e.g. "$var" / "${var}" work fine, but "$var.someProperty" / "${var}.someProperty" do not: you need "var.someProperty)" / "{var}.someProperty)"

In the context of "...", there is another reason to use ${...}, even if the variable name itself doesn't need it:

If you need to delineate the variable name from directly following non-whitespace characters, notably including ::

$foo = 'bar'  # example variable

# INCORRECT: PowerShell assumes that the variable name is 'foobarian', not 'foo'
PS> "A $foobarian."
A .  # Variable $foobarian doesn't exist -> reference expanded to empty string.

# CORRECT: Use {...} to delineate the variable name:
PS> "A ${foo}barian."
A barbarian.

# INCORRECT: PowerShell assumes that 'foo:' is a *namespace* (drive) reference
#            (such as 'env:' in $env:PATH) and FAILS:
PS> "$foo: bar"
Variable reference is not valid. ':' was not followed by a valid variable name character. 
Consider using ${} to delimit the name.

# CORRECT: Use {...} to delineate the variable name:
PS> "${foo}: bar"
bar: bar

See this answer for a comprehensive overview of PowerShell string-expansion rules.

Note that you need the same technique when string expansion is implicitly applied, in the context of passing an unquoted argument to a command; e.g.:

# INCORRECT: The argument is treated as if it were enclosed in "...",
#            so the same rules apply.
Write-Output $foo:/bar

# CORRECT
Write-Output ${foo}:/bar

Finally, a somewhat obscure alternative is to `-escape the first character after the variable name, but the problem is that this only works as expected with characters that aren't part of escape sequences (see about_Special_Characters):

# OK: because `: is not an escape sequence.
PS> "$foo`: bar"
bar: bar

# NOT OK, because `b is the escape sequence for a backspace character.
PS> "$foo`bar"
baar # The `b "ate" the trailing 'r' of the variable value
     # and only "ar" was the literal part.
2 of 3
35

Note that $() is helpful for json objects:

"My json property is jsonObj.property)"
🌐
Microsoft Learn
learn.microsoft.com › en-us › powershell › scripting › learn › deep-dives › everything-about-string-substitutions
Everything you wanted to know about variable substitution in strings - PowerShell | Microsoft Learn
June 8, 2025 - I'm calling this variable substitution but I'm referring to any time you want to format a string to include values from variables. This is something that I often find myself explaining to new scripters. ... The original version of this article appeared on the blog written by @KevinMarquette. The PowerShell team thanks Kevin for sharing this content with us.
Discussions

How to pass a varibale to a powershell script? - Chef Infra (archive) - Chef Questions
How to pass a varibale to a powershell script · As on pretty much all systems, single quotes do not allow string interpolation, so you need to use double quotes for your code string and escape the other double quotes · P.S.: Please use the means given to you by the system to format code blocks ... More on discourse.chef.io
🌐 discourse.chef.io
0
September 4, 2017
Enhanced String Interpolation

PowerShell only supports interpolation at the time of a variable creation, unless you are talking about calculated object properties:

https://docs.microsoft.com/en-us/powershell/module/microsoft.powershell.core/about/about_calculated_properties?view=powershell-7

If you are looking for f-strings see here: https://ss64.com/ps/syntax-f-operator.html

More on reddit.com
🌐 r/PowerShell
3
3
October 7, 2020
Come up with a better concat/string interpolation strategy
Moreover, we often need to embed non-variable expressions in the interpolated strings, for example: ... Output 'sshCommand' -Type 'string' -Value (concat 'ssh ' $adminUsername '@' (reference $publicIPAddressName).dnsSettings.fqdn) If we use a PowerShell string interpolation there: More on github.com
🌐 github.com
4
April 2, 2021
Support formatting specifiers in string interpolation
Summary of the new feature/enhancement It would be a great adddition to Powershell to support full-blown string interpolation, i.e. including the ability to specify the format of the expanded token... More on github.com
🌐 github.com
3
April 5, 2020
Top answer
1 of 3
200

tl;dr

Inside "...":

  • $(...) is only needed to embed entire expressions or commands (e.g. "PSVersionTable.PSVersion)")

  • ${...} is only needed if a stand-alone reference to a variable with a non-special name needs delimiting (disambiguation), so that subsequent characters in the string aren't interpreted as part of the variable name (e.g, "${foo}_bar" correctly embeds variable $foo; without {...}, PowerShell would look for variable $foo_bar; notably, a subsequent : requires this technique too: "${foo}:bar"; by contrast, something like "$foo!" also works without {...})

Independently of use in "...", ${...} is also needed for variable names containing special characters (e.g. ${a-b} = 42)

For a comprehensive overview of PowerShell's expandable strings (string interpolation), see this answer.


Background information:

To complement marsze's helpful answer:

${...} (enclosing the variable name in { and }) is indeed always necessary if a variable name contains special characters, such as spaces, . or -.

  • Not special are _ and - surprisingly and problematically - ?.

    • For the exact rules, see the relevant section of the conceptual "about_Variables" help topic, Variable Names that Include Special Characters.
  • (The first occurrence of) : in a name is invariably interpreted as terminating either a PowerShell drive reference - in the context of namespace variable notation - or a scope specifier, irrespective of whether {...} enclosure is used or required (e.g., in $env:USERNAME or ${env:USERNAME}, env refers to the Env: PowerShell drive representing all environment variables; in $script:foo or ${script:foo}, script refers to the script's scope and its variables).

Note:

  • ${...} - the syntax for disambiguating a variable name - is not to be confused with $(...), the subexpression operator, which is needed to embed any expression or command that goes beyond a stand-alone variable reference inside "...", an expandable (interpolating) string.

  • As such, these two syntax forms are independent of one another and may need to be combined in a given situation; e.g. "$var" / "${var}" work fine, but "$var.someProperty" / "${var}.someProperty" do not: you need "var.someProperty)" / "{var}.someProperty)"

In the context of "...", there is another reason to use ${...}, even if the variable name itself doesn't need it:

If you need to delineate the variable name from directly following non-whitespace characters, notably including ::

$foo = 'bar'  # example variable

# INCORRECT: PowerShell assumes that the variable name is 'foobarian', not 'foo'
PS> "A $foobarian."
A .  # Variable $foobarian doesn't exist -> reference expanded to empty string.

# CORRECT: Use {...} to delineate the variable name:
PS> "A ${foo}barian."
A barbarian.

# INCORRECT: PowerShell assumes that 'foo:' is a *namespace* (drive) reference
#            (such as 'env:' in $env:PATH) and FAILS:
PS> "$foo: bar"
Variable reference is not valid. ':' was not followed by a valid variable name character. 
Consider using ${} to delimit the name.

# CORRECT: Use {...} to delineate the variable name:
PS> "${foo}: bar"
bar: bar

See this answer for a comprehensive overview of PowerShell string-expansion rules.

Note that you need the same technique when string expansion is implicitly applied, in the context of passing an unquoted argument to a command; e.g.:

# INCORRECT: The argument is treated as if it were enclosed in "...",
#            so the same rules apply.
Write-Output $foo:/bar

# CORRECT
Write-Output ${foo}:/bar

Finally, a somewhat obscure alternative is to `-escape the first character after the variable name, but the problem is that this only works as expected with characters that aren't part of escape sequences (see about_Special_Characters):

# OK: because `: is not an escape sequence.
PS> "$foo`: bar"
bar: bar

# NOT OK, because `b is the escape sequence for a backspace character.
PS> "$foo`bar"
baar # The `b "ate" the trailing 'r' of the variable value
     # and only "ar" was the literal part.
2 of 3
35

Note that $() is helpful for json objects:

"My json property is jsonObj.property)"
🌐
Leyaa
leyaa.ai › codefly › learn › powershell › part-1 › powershell-string-type-and-interpolation › try
String type and interpolation in PowerShell - Interactive Code Practice | Leyaa.ai
Using ${count} inside double quotes ensures the variable name is clearly delimited for interpolation. ... Fill both blanks to create a string that includes a variable and a calculated expression.
🌐
Chef
discourse.chef.io › chef infra (archive)
How to pass a varibale to a powershell script? - Chef Infra (archive) - Chef Questions
September 4, 2017 - How to pass a varibale to a powershell script · As on pretty much all systems, single quotes do not allow string interpolation, so you need to use double quotes for your code string and escape the other double quotes · P.S.: Please use the ...
Find elsewhere
🌐
Reddit
reddit.com › r/powershell › enhanced string interpolation
r/PowerShell on Reddit: Enhanced String Interpolation
October 7, 2020 -

Hi everyone,

I'm certain PowerShell has this feature, but I can't remember the name of it.

I'm looking for formatting string using interpolation but where the string is interpolated at the time of reading it rather than at creation. In doing so, it takes the current value of the included variables rather than being stuck on the past contents of the variables. I think Python's f strings are what I'm after, but I could be wrong.

Any ideas?

🌐
SS64
ss64.com › ps › syntax-f-operator.html
PowerShell -f Format operator
Static text or more complex expressions may be included before or in-between the -f {format strings} The -F operator has equal precedence with Arithmetic operators, * / % + - etc, see About_Operator_Precedence When operators have equal precedence, PowerShell evaluates them from left to right.
🌐
Leyaa
leyaa.ai › codefly › learn › powershell › part-1 › powershell-string-type-and-interpolation › project
String type and interpolation in PowerShell Mini Project - Build & Apply | Leyaa.ai
Create a variable called $greeting and set it to a string that says Hello, my name is Alice and I am 30 years old. Use string interpolation with $name and $age inside double quotes.
🌐
GitHub
github.com › PowerShell › PSArm › issues › 144
Come up with a better concat/string interpolation strategy · Issue #144 · PowerShell/PSArm
April 2, 2021 - Moreover, we often need to embed non-variable expressions in the interpolated strings, for example: ... Output 'sshCommand' -Type 'string' -Value (concat 'ssh ' $adminUsername '@' (reference $publicIPAddressName).dnsSettings.fqdn) If we use a PowerShell string interpolation there:
Author   rjmholt
🌐
SharePoint Diary
sharepointdiary.com › sharepoint diary › powershell › how to use string interpolation in powershell?
How to Use String Interpolation in PowerShell? - SharePoint Diary
September 19, 2025 - Here’s a quick comparison to show how string interpolation makes things easier: ... # Without interpolation $name = "Smith" $message = "Hello, " + $name + "! Welcome to PowerShell." Write-Output $message # With interpolation $name = "Smith" $message = "Hello, $name!
🌐
LazyAdmin
lazyadmin.nl › home › how to concatenate a string in powershell
How to Concatenate a String in PowerShell — LazyAdmin
December 8, 2022 - In this article, we will look at the different methods to join multiple strings in PowerShell.
🌐
Microsoft Learn
learn.microsoft.com › en-us › powershell › module › microsoft.powershell.core › about › about_quoting_rules
about_Quoting_Rules - PowerShell | Microsoft Learn
September 29, 2025 - To separate a variable name from subsequent characters in the string, enclose it in braces ({}). This is especially important if the variable name is followed by a colon (:). PowerShell considers everything between the $ and the : a scope specifier, ...
🌐
Arcane Code
arcanecode.com › 2021 › 07 › 12 › fun-with-powershell-strings
Fun With PowerShell Strings – Arcane Code
July 15, 2021 - String interpolation will take any variables embedded in the string and expand them before returning the string.
🌐
Easy IT Tutorials
easyittutorials.wordpress.com › 2020 › 01 › 16 › powershell-string-concatenation-and-interpolation
PowerShell: String Concatenation and Interpolation – Easy IT Tutorials
January 16, 2020 - By using string interpolation, we can connect a set of strings and variables with only 1 set of quotation marks, and without the ‘+’ operator, which makes the whole string much easier to read and interpret.
🌐
GitHub
github.com › PowerShell › PowerShell › issues › 12259
Support formatting specifiers in string interpolation · Issue #12259 · PowerShell/PowerShell
April 5, 2020 - I assume C# implements this by parsing the $ string and turning it into a concatenation of the parts where the interpolated expression is simply passed to string.Format. Not sure if Powershell also needs a special character. But it's maybe not a bad idea to keep a familiar syntax like C#'s i.e.
Author   stinos
🌐
ShellGeek
shellgeek.com › home › powershell tips › string interpolation in powershell
String Interpolation in PowerShell - ShellGeek
April 14, 2024 - String Interpolation in PowerShell is the way of replacing the value of a variable into placeholders in a string. It displays variable value
🌐
IT Pro Today
itprotoday.com › powershell › advanced-string-manipulation-techniques-in-powershell
Advanced String Manipulation Techniques in PowerShell
June 28, 2024 - ITPro Today, Network Computing and IoT World Today have combined with TechTarget.com. The page you are looking for may no longer exist.
🌐
Red Gate Software
red-gate.com › home › working with powershell strings
Working with PowerShell strings | Simple Talk
November 24, 2021 - The upside is that it’s very easy to write out strings with the value of the variables embedded directly in the string. The downside is that you can’t easily print out the variable’s name, which you may want to do while debugging a script. The following example, SimpleStrings_with_variables_demo_2.ps1 shows a few ways of solving that problem: You will notice the backtick character ` allows you to escape the $ so that PowerShell does not treat the characters that follow as a variable name.