CmdID / PowerShell / Cmdlets / Format
Format-Hex
Displays a file or other input as hexadecimal. PowerShell reference
From the PowerShell reference
5 parameters
Alias fhx
What it does
Displays a file or other input as hexadecimal. The Format-Hex cmdlet displays a file or other input as hexadecimal values. To determine the offset of a character from the output, add the number at the leftmost of the row to the number at the top of the column for that character. The Format-Hex cmdlet can help you determine the file type of a corrupted file or a file that might not have a filename extension. You can run this cmdlet, and then read the hexadecimal output to get file information. When using Format-Hex on a file, the cmdlet ignores newline characters and returns the entire contents of a file in one string with the newline characters preserved.
Format-Hex [-Path] <string[]> [<CommonParameters>]Format-Hex -LiteralPath <string[]> [<CommonParameters>]Format-Hex -InputObject <Object> [-Encoding <string>] [-Raw] [<CommonParameters>]
Get the hexadecimal representation of a string
'Hello World' | Format-HexIdentifyFind a file type from hexadecimal output
Format-Hex -Path .\File.t7fIdentifyDisplay raw hexadecimal output
PS> 1,2,3,1000 | Format-Hex
Path:
00 01 02 03 04 05 06 07 08 09 0A 0B 0C 0D 0E 0F
00000000 01 02 03 E8 03 ...è.
PS> 1,2,3,1000 | Format-Hex -Raw
Path:
00 01 02 03 04 05 06 07 08 09 0A 0B 0C 0D 0E 0F
00000000 01 00 00 00 02 00 00 00 03 00 00 00 E8 03 00 00 ............è...IdentifyIts page in the reference: Format-Hex.
Parameters
-EncodingSpecifies the encoding of the output. This only applies to [string] input. The parameter has no effect on numeric types. The default value is ASCII.
The acceptable values for this parameter are as follows:
- Ascii Uses ASCII (7-bit) character set.
- BigEndianUnicode Uses UTF-16 with the big-endian byte order.
- Unicode Uses UTF-16 with the little-endian byte order.
- UTF7 Uses UTF-7.
- UTF8 Uses UTF-8.
- UTF32 Uses UTF-32 with the little-endian byte order.
Non-ASCII characters in the input are output as literal ? characters resulting in a loss of information.-InputObjectSpecifies the objects to be formatted. Enter a variable that contains the objects or type a command or expression that gets the objects.
Only certain scalar types and [System.IO.FileInfo] are supported.
The supported scalar types are:
- [string]
- [byte]
- [int], [int32]
- [long], [int64]-LiteralPathSpecifies the complete path to a file. The value of LiteralPath is used exactly as it is typed. This parameter does not accept wildcard characters. To specify multiple paths to files, separate the paths with a comma. If the LiteralPath parameter includes escape characters, enclose the path in single quotation marks. PowerShell does not interpret any characters in a single quoted string as escape sequences. For more information, see about_Quoting_Rules.-PathSpecifies the path to files. Use a dot (.) to specify the current location. The wildcard character (*) is accepted and can be used to specify all the items in a location. If the Path parameter includes escape characters, enclose the path in single quotation marks. To specify multiple paths to files, separate the paths with a comma.-RawBy default Format-Hex opts for compact output of numeric data types: single-byte or double-byte sequences are used if the value is small enough. The Raw parameter deactivates this behavior.