How to use the "-join" command after the pipeline

I train in powershell 3.0, and I try to get the contents of the file in bytes by sending it along the pipeline to join the result, by default there is one byte per line, and then send the result in the file.

Here's the command I'm using:

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

So, to summarize, does anyone know how to use -joinafter the pipeline?

+4
source share
1 answer

You cannot -joinpipeline, because the pipeline stage only sees one object at a time.

Instead, handle the collection returned get-contentas a single object and attach it.

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

Source: https://habr.com/ru/post/1546143/


All Articles