2016-07-19 7 views
1

でスクリプト

Get-ADComputer -Filter '*'| ForEach-Object { 
    Write-output "testing $_.DnsHostName" 
    #Do more with $_ 
} 

の以下のスニペットを実行している場合は、私が得る:

testing CN=CO-ID96407D,OU=Contoso Computers,OU=Contoso Organisation,DC=contoso.DnsHostName 

しかし、私は期待していこと

testing CO-ID96407D.contoso 

で、誰もが私がここで間違ってやっているのか分かりません私はちょうど$_DnsHostNameのメンバーを出力したいと思うが、ちょうどAD-Computerのデフォルト出力メンバーを出力しているようであるject。

答えて

2

あなたは$(...)でそれを包む必要があり、したがって文字列の部分式を作成している:

Write-output "testing $($_.DnsHostName)" 

それとも、フォーマット文字列を使用することができます

Write-output "testing {0}" -f $_.DnsHostName 
1
Write-output "testing $($_.DnsHostName)" 
関連する問題