Copied shamelessly from SO on dumping hex values from binary file, and back. Thought VSCode could do the job, but the official hex editor does not quite support copy-paste.
# read the binary data as byte array [byte[]]$data = [System.IO.File]::ReadAllBytes('D:\Test\blah.exe') # write to new file as string of hex encoded characters [System.IO.File]::WriteAllText('D:\Test\blah.hex',[System.BitConverter]::ToString($data).Replace('-',''), [System.Text.Encoding]::ASCII)
# read the textfile as single ASCII string $hex = [System.IO.File]::ReadAllText('D:\Test\blah.hex', [System.Text.Encoding]::ASCII) # convert to bytes and write these as new binary file [System.IO.File]::WriteAllBytes('D:\Test\blahblah.exe', ($hex -split '(.{2})' -ne '' -replace '^', '0X'))