File Hashing with Powershell

I’ve been a contractor for a long time, namely because I preferred to jump from business to business learning new things, facing new challenges.  Early in my career when I stayed put in a single firm, I was easily bored. (Although as I get older, the idea of consistency and belonging is slowly beginning to appeal to me…but, that’s another post for another time).

One of the issues with hopping from business to business is that I never know what systems/applications are available to me.  Sometimes a firm will have the best and latest bleeding-edge technology, and other times (probably more often) all that’s available is whatever happens to be in the personal arsenal of the individual working on the project at the time.

This is why I like tools that are free or open-source.  I can have them anytime without being required to go through a committee with requisition forms in triplicate just to get a minor task completed.  Convincing a client that the $60 he is trying to save on software would end up costing him thousands in extra labor hours, is a conversation that gets repetitive and annoying very fast.

PowerShell (and Python) has become part of my toolset for the simple reason that it is readily available, and the functions it provides are practically all-encompassing.

One of the commands in PowerShell I like to use quite often is:

Get-FileHash

Say I wanted to get the MD5 hash of the file cindyloh3333@gmail.com.mbox shown in the screenshot above.  All I’d have to do is type in:

get-filehash -algorithm md5 cindyloh3333@gmail.com.mbox

The -algorithm md5 option specifies the hashing algorithm to be used and I can just as easily change it to SHA1, SHA256, or any other algorithm that may be appropriate.  Also, by adding in the pipe | and out-file command, I can even export the information into a text file for later use:

get-filehash -algorithm md5 cindyloh3333@gmail.com.mbox | out-file "C:\temp\hashed.txt"

And, with a little bit more added to the initial command, I can even have all the files within a specific path hashed and exported out to a CSV file:

Get-FileHash -Algorithm MD5 -Path (Get-ChildItem "C:\Temp\Hashing\*.*" -Recurse -force) | export-csv c:\Temp\allfiles_hashed.csv

Though most of the time I would just go with the less elegant (but much easier to type):

$name = get-filehash -algorithm md5 "c:temphashing*.*" ; $name | out-file "c:tempcombinedhash.txt"

Though it won’t give me a CSV file, it’s easier for me to remember as it’s really just combining two simple operations (storing the hashes in a variable, and then saving that variable to a text file); plus it’s one of the first piece of “code” that I figured out on my own when I first started learning PowerShell many many moons ago 🙂

The point here though is that PowerShell obviously packs quite a bit under the hood and isn’t just for system admins to manage servers and networks.  There are many different scenarios in Legal Tech where PowerShell is my go-to option due to the fact that 1) it’s readily available everywhere on every OS, and 2) for one-off needs, it doesn’t require a huge time investment.

Written by Andrew

Recent News

Legal Billing

Many many moons ago, when I first ...

Relativity Fest – Scholarship

Relativity Fest is just around the corner: ...

Information Governance – Simplified

When you first begin to study eDiscovery, ...