Show-BinaryFile – A hex viewer in PowerShell

In my previous post I showed you a couple of wrapper functions I made to handle binary to string conversion (and vice versa). Building on one of these I thought it would be fun to try to make a simple file hex viewer, similar to how popular hex editors work (without the editing part of course).

The function opens a filestream and uses a binary reader object to read the file, then pipes the result to my wrapper function called Invoke-CryptBinaryToString that shows a string representation of the file in hex as well as in ASCII. Optionally you can also add address fields using the ShowAddress parameter.

This means that you need to have my code from the previous post loaded in memory to be able to use this one.

The function also lets you choose where to start and how many bytes it should read, in case you only want to look at particular sections of the file.


Hope you find this one interesting. Catch you on the next one!

UPDATE! As Kirk mentions in his comment down below, this functionality is in fact natively supported in PowerShell version 5! So no need for my function at all if you are using v5. 🙂


  1. Did you know you can do this natively with Format-Hex in PowerShell 5?

    Format-Hex -Path $pathToBinaryFile | Select-Object -First 4
    Format-Hex -Path $pathToBinaryFile | Select-Object -First 16

    You even get back .NET objects so you could filter on an address range by using the Offset property.

    I thought it was worth pointing this functionality out since it is available out of the box with PowerShell 5.


    1. Thank you for your comment Kirk. No, I didn’t know, so tanks for bringing it to my attention! I love learning new stuff 🙂 This was just a spin-off idea based on my previous post, so I thought it would be a cool function.. turns out it’s not needed at all 😀


  2. What versions will your script work with? Or what version was it written in? There’s always a need for scripts to do things in prior versions… not all of us can upgrade immediately at work. In addition, I find it awesome that you coded this, AND other people thought it was useful enough to put into v5. Kirk, thanks for pointing it out, too!


Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s