2014-06-26 44 views
4

我在使用powershell 3.0進行培訓,我試圖以字節爲單位獲取文件內容,通過管道發送它以便按默認方式加入結果每行有一個字節,然後將結果發送到一個文件中。如何在管道後使用「-join」命令

下面是我使用的命令:

get-content 'My file' -Encoding byte | $_ -join ' ' | Out-File -path 'My result file' 

所以總結一下,沒有人知道如何在管道後使用-join

回答

8

您不能通過管道執行-join,因爲管道階段一次只能看到一個對象。

相反,將get-content返回的集合視爲單個對象並加入。

(get-content -path 'my file' -Encoding Byte) -join ' ' | out-file -path 'My result file'; 
+0

謝謝,它的工作原理;) – DoT