A subexpression is an expression nested inside a larger expression. In PowerShell, $() evaluates a command and inserts its result into a double-quoted string. section 16.5
Insert the first process name
Use $() when indexing or accessing a property inside a string: $processes = Get-Process; $firstname = "The first name is $($processes[0].name)". The command produces a sentence containing the first process name, unlike direct interpolation of "$processes[0].name". section 16.5
Subexpressions also group expressions for other kinds of evaluation:
- Regular expressions use parentheses to group a repeating unit, as in (ca)+r, which matches repeated ca sequences before r. section 21.2
- PowerShell logical operators accept a subexpression on each side, such as (5 -gt 10) -or (10 -lt 100). section 12.3
$processes = Get-Process | where-object {$_.Name}
$firstname = "The first name is $($processes[0].name)"
$firstname
Run this listing to see a subexpression evaluate a process property inside a double-quoted string. section 16.5

