I'm training in powershell 3.0 and i'm trying to get the content of a file in bytes, sending it through a pipeline in order to join the result as by default there's one byte per line, and then send the result in a 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 someone know how to use a -join
after a pipeline?
You can't do the -join
via the pipeline because the pipeline stage only sees one object at a time.
Instead, treat the collection returned by get-content
as a single object and join that.
(get-content -path 'my file' -Encoding Byte) -join ' ' | out-file -path 'My result file';