What does $($variableName) mean in expandable strings in PowerShell?

The syntax helps with evaluating the expression inside it.

$arr = @(1,2,3)

$msg1 = "$arr.length"
echo $msg1 # prints 1 2 3.length - .length was treated as part of the string

$msg2 = "$($arr.length)"
echo $msg2 # prints 3

You can read more at http://ss64.com/ps/syntax-operators.html

Leave a Comment