This browser is no longer supported.
Upgrade to Microsoft Edge to take advantage of the latest features, security updates, and technical support.
Note
Access to this page requires authorization. You can trysigning in orchanging directories.
Access to this page requires authorization. You can trychanging directories.
Displays a file or other input as hexadecimal.
Format-Hex [-Path] <String[]> [-Count <Int64>] [-Offset <Int64>] [<CommonParameters>]
Format-Hex -LiteralPath <String[]> [-Count <Int64>] [-Offset <Int64>] [<CommonParameters>]
Format-Hex -InputObject <PSObject> [-Encoding <Encoding>] [-Count <Int64>] [-Offset <Int64>] [-Raw] [<CommonParameters>]
TheFormat-Hex
cmdlet displays a file or other input as hexadecimal values. To determine theoffset of a character from the output, add the number at the leftmost of the row to the number atthe top of the column for that character.
TheFormat-Hex
cmdlet can help you determine the file type of a corrupted file or a file thatmight not have a filename extension. You can run this cmdlet, and then read the hexadecimal outputto get file information.
When usingFormat-Hex
on a file, the cmdlet ignores newline characters and returns the entirecontents of a file in one string with the newline characters preserved.
This command returns the hexadecimal values of a string.
'Hello World' | Format-Hex
Label: String (System.String) <2944BEC3> Offset Bytes Ascii 00 01 02 03 04 05 06 07 08 09 0A 0B 0C 0D 0E 0F ------ ----------------------------------------------- -----0000000000000000 48 65 6C 6C 6F 20 57 6F 72 6C 64 Hello World
The stringHello World is sent down the pipeline to theFormat-Hex
cmdlet. The hexadecimaloutput fromFormat-Hex
shows the values of each character in the string.
This example uses the hexadecimal output to determine the file type. The cmdlet displays the file'sfull path and the hexadecimal values.
To test the following command, make a copy of an existing PDF file on your local computer and renamethe copied file toFile.t7f
.
Format-Hex -Path .\File.t7f -Count 48
Label: C:\Test\File.t7f Offset Bytes Ascii 00 01 02 03 04 05 06 07 08 09 0A 0B 0C 0D 0E 0F ------ ----------------------------------------------- -----0000000000000000 25 50 44 46 2D 31 2E 35 0D 0A 25 B5 B5 B5 B5 0D %PDF-1.5..%????.0000000000000010 0A 31 20 30 20 6F 62 6A 0D 0A 3C 3C 2F 54 79 70 .1 0 obj..<</Typ0000000000000020 65 2F 43 61 74 61 6C 6F 67 2F 50 61 67 65 73 20 e/Catalog/Pages
TheFormat-Hex
cmdlet uses thePath parameter to specify a filename in the current directory,File.t7f
. The file extension.t7f
is uncommon, but the hexadecimal output%PDF
shows that itis a PDF file. In this example, theCount parameter is used to limit the output to the first 48bytes of the file.
This example uses an array of different data types to highlight howFormat-Hex
handles them in thePipeline.
It will pass each object through the Pipeline and process individually. However, if it's numericdata, and the adjacent object is also numeric, it will group them into a single output block.
'Hello world!', 1, 1138, 'foo', 'bar', 0xdeadbeef, 1gb, 0b1101011100 , $true, $false | Format-Hex
Label: String (System.String) <24F1F0A3> Offset Bytes Ascii 00 01 02 03 04 05 06 07 08 09 0A 0B 0C 0D 0E 0F ------ ----------------------------------------------- -----0000000000000000 48 65 6C 6C 6F 20 77 6F 72 6C 64 21 Hello world! Label: Int32 (System.Int32) <2EB933C5> Offset Bytes Ascii 00 01 02 03 04 05 06 07 08 09 0A 0B 0C 0D 0E 0F ------ ----------------------------------------------- -----0000000000000000 01 00 00 00 72 04 00 00 � r� Label: String (System.String) <4078B66C> Offset Bytes Ascii 00 01 02 03 04 05 06 07 08 09 0A 0B 0C 0D 0E 0F ------ ----------------------------------------------- -----0000000000000000 66 6F 6F foo Label: String (System.String) <51E4A317> Offset Bytes Ascii 00 01 02 03 04 05 06 07 08 09 0A 0B 0C 0D 0E 0F ------ ----------------------------------------------- -----0000000000000000 62 61 72 bar Label: Int32 (System.Int32) <5ADF167B> Offset Bytes Ascii 00 01 02 03 04 05 06 07 08 09 0A 0B 0C 0D 0E 0F ------ ----------------------------------------------- -----0000000000000000 EF BE AD DE 00 00 00 40 5C 03 00 00 ï¾-Þ @\� Label: Boolean (System.Boolean) <7D8C4C1D> Offset Bytes Ascii 00 01 02 03 04 05 06 07 08 09 0A 0B 0C 0D 0E 0F ------ ----------------------------------------------- -----0000000000000000 01 00 00 00 00 00 00 00 �
This represents the number of bytes to include in the hex output.
This parameter was introduced in PowerShell 6.2.
Type: | Int64 |
Default value: | Int64.MaxValue |
Supports wildcards: | False |
DontShow: | False |
Position: | Named |
Mandatory: | False |
Value from pipeline: | False |
Value from pipeline by property name: | False |
Value from remaining arguments: | False |
Specifies the encoding of the input strings. This only applies to[string]
input. The parameterhas no effect on numeric types. The output value is alwaysutf8NoBOM
.
The acceptable values for this parameter are as follows:
ascii
: Uses the encoding for the ASCII (7-bit) character set.ansi
: Uses the encoding for the for the current culture's ANSI code page. This option was addedin PowerShell 7.4.bigendianunicode
: Encodes in UTF-16 format using the big-endian byte order.bigendianutf32
: Encodes in UTF-32 format using the big-endian byte order.oem
: Uses the default encoding for MS-DOS and console programs.unicode
: Encodes in UTF-16 format using the little-endian byte order.utf7
: Encodes in UTF-7 format.utf8
: Encodes in UTF-8 format.utf8BOM
: Encodes in UTF-8 format with Byte Order Mark (BOM)utf8NoBOM
: Encodes in UTF-8 format without Byte Order Mark (BOM)utf32
: Encodes in UTF-32 format.Beginning with PowerShell 6.2, theEncoding parameter also allows numeric IDs of registered codepages (like-Encoding 1251
) or string names of registered code pages (like-Encoding "windows-1251"
). For more information, see the .NET documentation forEncoding.CodePage.
Starting with PowerShell 7.4, you can use theAnsi
value for theEncoding parameter to passthe numeric ID for the current culture's ANSI code page without having to specify it manually.
Note
UTF-7* is no longer recommended to use. As of PowerShell 7.1, a warning is written if youspecifyutf7
for theEncoding parameter.
Type: | Encoding |
Default value: | UTF8NoBOM |
Accepted values: | ASCII, BigEndianUnicode, BigEndianUTF32, OEM, Unicode, UTF7, UTF8, UTF8BOM, UTF8NoBOM, UTF32 |
Supports wildcards: | False |
DontShow: | False |
Position: | Named |
Mandatory: | False |
Value from pipeline: | False |
Value from pipeline by property name: | False |
Value from remaining arguments: | False |
Specifies the objects to be formatted. Enter a variable that contains the objects or type a commandor expression that gets the objects.
Only certainscalar types and[System.IO.FileInfo]
are supported.
The supported scalar types are:
[string]
,[char]
[byte]
,[sbyte]
[int16]
,[uint16]
,[short]
,[ushort]
[int]
,[uint]
,[int32]
,[uint32]
,[long]
,[ulong]
,[int64]
,[uint64]
[single]
,[float]
,[double]
[boolean]
Prior to PowerShell 6.2,Format-Hex
would handle a Pipeline input with multiple input types bygrouping all like objects together. Now, it handles each individual object as it passes through thePipeline and won't group objects together unless like objects are adjacent.
Type: | PSObject |
Default value: | None |
Supports wildcards: | False |
DontShow: | False |
Position: | Named |
Mandatory: | True |
Value from pipeline: | True |
Value from pipeline by property name: | False |
Value from remaining arguments: | False |
Specifies the complete path to a file. The value ofLiteralPath is used exactly as it is typed.This parameter does not accept wildcard characters. To specify multiple paths to files, separate thepaths with a comma. If theLiteralPath parameter includes escape characters, enclose the path insingle quotation marks. PowerShell does not interpret any characters in a single quoted string asescape sequences. For more information, seeabout_Quoting_Rules.
Type: | String[] |
Default value: | None |
Supports wildcards: | False |
DontShow: | False |
Aliases: | PSPath, LP |
Position: | Named |
Mandatory: | True |
Value from pipeline: | False |
Value from pipeline by property name: | False |
Value from remaining arguments: | False |
This represents the number of bytes to skip from being part of the hex output.
This parameter was introduced in PowerShell 6.2.
Type: | Int64 |
Default value: | 0 |
Supports wildcards: | False |
DontShow: | False |
Position: | Named |
Mandatory: | False |
Value from pipeline: | False |
Value from pipeline by property name: | False |
Value from remaining arguments: | False |
Specifies 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 thePath parameterincludes escape characters, enclose the path in single quotation marks. To specify multiple paths tofiles, separate the paths with a comma.
Type: | String[] |
Default value: | None |
Supports wildcards: | True |
DontShow: | False |
Position: | 0 |
Mandatory: | True |
Value from pipeline: | False |
Value from pipeline by property name: | False |
Value from remaining arguments: | False |
This parameter no longer does anything. It is retained for script compatibility.
Type: | SwitchParameter |
Default value: | None |
Supports wildcards: | False |
DontShow: | False |
Position: | Named |
Mandatory: | False |
Value from pipeline: | False |
Value from pipeline by property name: | False |
Value from remaining arguments: | False |
This cmdlet supports the common parameters: -Debug, -ErrorAction, -ErrorVariable,-InformationAction, -InformationVariable, -OutBuffer, -OutVariable, -PipelineVariable,-ProgressAction, -Verbose, -WarningAction, and -WarningVariable. For more information, seeabout_CommonParameters.
You can pipe a string to this cmdlet.
This cmdlet returns aByteCollection. This object represents a collection of bytes. It includesmethods that convert the collection of bytes to a string formatted like each line of output returnedbyFormat-Hex
. The output also states they type of bytes being processed. If you specify thePath orLiteralPath parameter, the object contains the path of the file that containseach byte. If you pass a string, boolean, integer, etc, it will be labeled appropriately.
PowerShell includes the following aliases forFormat-Hex
:
fhx
The right-most column of output tries to render the bytes as ASCII characters:
Generally, each byte is interpreted as a Unicode code point, which means that:
NUL
.Was this page helpful?
Was this page helpful?