Using Subexpressions Within Strings In Powershell
The aim of this pageđ is to share the use and weirdness of PowerShellâs Subexpression operator $( )
notation. Weird, because if you are combining the use of a subexpression operator with a variable name â it's "two dollars" $($
. In bash, there indeed is command substitution and this is somewhat similar.
echo "the length is $($list.length)"
echo "today is $(Get-Date)"
- the following example is used for a logger to stdout when printing a many jobs at once and I want to see the progress (e.g
job# 3/15
)
$i = 1
foreach ($jobId in $jobIds) {
if($jobIds.length -gt 1) {
Write-Host "-- Dwarf Counts: Job #${i}/$($jobIds.length) --" -backgroundcolor DarkYellow-foregroundcolor Magenta
$i++
Pause}
}