Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to pipe binary data in PowerShell

Tags:

powershell

I tried to extract the Master Boot Record (MBR) via mmcat.exe in PowerShell and PowerShell ISE (Version 5.1.1). The outputted binary data is always bigger than 512 bytes. PowerShell 6.1.1 has still this problem.

$mmcat = "C:\Tools\sleuthkit\bin\mmcat.exe"
& $mmcat -t dos "$EWF_IMAGE" 0 > "$OUTPUT\Disk-Geometry\MBR.bin"

The issue is well decribed here: PowerShell’s Object Pipeline Corrupts Piped Binary Data

Do you know a workaround for this?

like image 818
user3022917 Avatar asked Nov 07 '22 22:11

user3022917


1 Answers

PowerShell 7 support -AsByteStream to pipe binary data:

Get-Content -AsByteStream .\original.bin | Set-Content -AsByteStream .\copied-file.bin

If you want to concatenate binary file use Add-Content:

Get-Content -AsByteStream .\original.bin | Add-Content -AsByteStream .\appended-file.bin
like image 119
dns Avatar answered Nov 15 '22 05:11

dns