Something like this should work. I tested it on a text file so it’s easy to see the result but it should work the same for binary files.
The text file just contained the word ‘hello’, and the code replaces the first two letters.
#Read in the text file as bytes $bytes = Get-Content E:\Temp\filea.txt -Encoding Byte -ReadCount 0 #Convert the bytes to hex $hexString = [System.BitConverter]::ToString($bytes) #Replace 'h' and 'e' with 'f' and 'g' $newHexString = $hexString -replace '68-65','66-67' #Convert the hex back to bytes $newBytes = $newHexString.Split('-') | foreach {[byte]::Parse($_, 'hex')} #Update the contents of the file $newBytes | Set-Content E:\Temp\filea.txt -Encoding Byte