Using Write-Host in a $() subexpression always outputs to the beginning of a string, regardless of its position.
For example:
"This is $(Write-Host 'now at the beginning' -NoNewline)"
Outputs:
now at the beginningThis is
Other cmdlets work as expected here (e.g. "Today is $((Get-Date).DayOfWeek)", Today is Friday).
How is Write-Host different?
Write-Hostwrite string to host and not return anything.