PowerShell Compare-Hash Function

Quite some time ago I created a PowerShell function which allowed one to compare a given cryptographic hash against one locally generated to see if they match. Looking back on the old version (here is a link to the blog article https://www.bytesizedalex.com/powershell-cryptographic-hash-checker/) it is very much reminiscent of old school batch files. I decided now I am more familiar with PowerShell function creation it would be a good idea to take a second go at it.

I’ve added this version to my GitHub repository – https://github.com/bytesizedalex/compare-hash

The function is pretty simple and leverages the existing Get-FileHash cmdlet to generate the cryptographic hash. All I’ve done is add a comparison so you can provide the hash you have against the one it generates. The function will simply state ‘MATCH’ or ‘NO MATCH’ to indicate if they are the same or not, I find this handy when I want to check a download or copied file.

PowerShell Compare-Hash Function Examples

I find it really interesting to look back on something I wrote nearly two years ago, I feel like this new version is certainly an improvement and something I’m much happier with.

Leave a Reply