Thursday, 14 April 2016

Comparing MD5 hashes with PowerShell

I do very much appreciate when software publishers publish the MD5 hashes of their binaries or image files. This way I can verify that a file has not changed as a result of a faulty file transfer, a disk error or other manipulation.
PowerShell has a (not very well known) cmdlet for creating MD5 hashes - Get-FileHash.
However, this was still to manual for me. Compute the file hash, read the hash from the .md5 file and manually compare the hashes.
Therefore I wrote myself a small PowerShell script that required two parameters - the path to the binary or image file and the path to the .md5 file. It assumes that the hash is the first 32 characters in the .md5 file.

An example how to run the script would be:

PS C:\Users\admin\Downloads> .\Check-Md5Sum -param1 .\windows81.iso -param2 .\windows81.md5

No comments:

Post a Comment