I have written a PS script and for diagnos开发者_JS百科tic 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:
"Foo $($bar.Property)"
Try this:
$dir = ls
Write-Host "Dir elements:" $dir.Length
精彩评论