I have written a PS script and for diagnostic purpose am echoing messages to screen using Write-Host. This is fine as long as I have to expand normal variable like
Write-Host "Hello World, $name"
Problem starts when i try to echo some member variable as below
Write-Host "Hello World, $Person.Name"
This does not expand as expected. The work around that am following is, to use temp variable
as below
$personName = $Person.Name
Write-Host "Hello World, $personName"
Is there an elegant way of doing this with out the use of temp variable?
If you want to use property access within double-quoted strings, you need a subexpression: