I want to pipe the output of a command to a file:
PS C:\Temp> create-png > binary.png
I noticed that Powershell changes the encoding and that I can manually give an encoding:
PS C:\Temp> create-png | Out-File "binary.png" -Encoding OEM
However there is no RAW encoding option, even the OEM option changes newline bytes (0xA
resp 0xD
) to the windows newline byte sequence (0xD 0xA
) thereby ruining any binary format.
How can I prevent Powershell from changing the encoding when piping to a file?
Related questions
According to this well written blog article
Try using set-content:
If you need additional info on set-content just run
You can also use 'sc' as a shortcut for set-content.
Tested with the following, produces a readable PNG:
If you are calling out to a non-PowerShell executable like ipconfig and you just want to capture the bytes from Standard Output, try Start-Process:
Create a batchfile containing the line
and call that from Powershell via
If you'd rather pass the command to cmd as command line parameter: