Format-Hex

Display a file or other input as hexadecimal.

Syntax
      Format-Hex [-Encoding {Ascii | UTF32 | UTF7 | UTF8 | BigEndianUnicode | Unicode}]
         -InputObject Object [-Raw] [CommonParameters]

      Format-Hex -LiteralPath String[] [CommonParameters]

      Format-Hex [-Path] String[] [CommonParameters]

Key:
   -Encoding String
      Specifies the type of character encoding used in the file that this cmdlet formats as hexadecimal. The 
      acceptable values for this parameter are: Ascii,UTF32,UTF7,UTF8,BigEndianUnicode,Unicode        
      The default value is Unicode.

   -InputObject Object
      Used for pipeline input.
      Pipeline input supports only certain scalar types and [system.io.fileinfo] instances for piping from Get-ChildItem.
      The supported scalar types are: [string],[byte],[int],[int32],[long], [int64]
        
   -LiteralPath String[]
      An array of literal paths of items. This parameter does not accept wildcard characters.
      To specify multiple paths to files, separate the paths with a comma. 
      To use wildcard characters, specify the -Path parameter instead.
        
      If this parameter includes escape characters, enclose the path in single quotation marks.
        
   -Path String[]
      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.
        
   -Raw
      By 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.

Standard Aliases for Format-Hex: fhx

Format-Hex 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. This cmdlet can help you determine the file type of a corrupted file or a file which may not have a file name extension. Run this cmdlet, and then inspect the results for file information.

Examples

Get the hexadecimal representation of the string 'Hello World':

PS C:\> "Hello World" | Format-Hex
            00 01 02 03 04 05 06 07 08 09 0A 0B 0C 0D 0E 0F
 00000000   48 65 6C 6C 6F 20 57 6F 72 6C 64              Hello World

Investigate a file type:

This command converts the file that is named temp.t7f to hexadecimal. In this example, a file that has the unfamiliar file name extension .t7f is actually a PDF file. The first few bytes of the header contain that information.

PS C:\> Format-Hex -Path "C:\temp\temp.t7f"
               00 01 02 03 04 05 06 07 08 09 0A 0B 0C 0D 0E 0F
    
    00000000   25 50 44 46 2D 31 2E 35 0D 0A 25 B5 B5 B5 B5 0D  %PDF-1.5..%????. 
    00000010   0A 31 20 30 20 6F 62 6A 0D 0A 3C 3C 2F 54 79 70  .1 0 obj..<</Typ
    00000020   65 2F 43 61 74 61 6C 6F 67 2F 50 61 67 65 73 20  e/Catalog/Pages

“The S/360 was the single biggest mistake in computing history. April 7 is a day that will live in infamy because it's the day the computing world became saddled with the hexadecimal numbering system” ~ Barry Gordon

Related PowerShell Cmdlets:

-f operator - Format values as Hex.
format-custom - Format output using a customized view.
format-list - Format output as a list of properties, each on a new line.
format-wide - Format objects as a table of their properties.


 
Copyright © 1999-2020 SS64.com
Some rights reserved