我試圖做到以下幾點:如何在PowerShell中獲取字符串而不是數組?
$files = Get-ChildItem c:\temp | Select-Object Name
foreach ($i in $files) {
Write-Host "Filename is $i"
}
樣品結果:
Filename is @{Name=oracle10204.rsp}
Filename is @{Name=powershell.txt}
我怎麼只有以下?
Filename is oracle10204.rsp
Filename is powershell.txt
謝謝,你的例子有效,但如何讓我的foreach語句給出正確的結果? – jrara
@jrara - 我是說不要使用你的foreach語句,因爲這是一樣的事情,但更有效的方法。流水線是PowerShell設計的。 – JNK
嗯,是的,但我想學習PowerShell,我想知道我的foreach循環出了什麼問題。我知道還有很多其他的方法可以做到這一點。 – jrara