I am able to get the byte code but 2 things I am trying to do here is
gc -Raw -encoding byte "c:\picture.jpg" | % {write-host ('{0:x}' -f $_) -noNewline};
tried trim() but not sure if that is possible or where to put it.
The simplest - and most efficient - solution is to use .NET APIs:
In Windows PowerShell, use System.BitConverter.ToString
, and remove the resulting -
separators afterwards:
[System.BitConverter]::ToString(
(Get-Content -Raw -Encoding Byte c:\picture.jpg)
) -replace '-'
In PowerShell (Core) 7+, use System.Convert.ToHexString
, which directly yields the desired format:
[System.Convert]::ToHexString(
(Get-Content -Raw -AsByteStream c:\picture.jpg)
)
Note:
-Encoding Byte
to -AsByteStream
that occurred between the two PowerShell editions - see GitHub issue #7986.