MD5SUM via PowerShell (when you don’t have Get-FileHash)

Written by James McDonald

August 28, 2015

SBS 2011 doesn’t allow you to install Powershell v4 which has a one line Get-FileHash utility to generate an md5sum. So you need a few extra lines.

I needed to transfer some PSTs which I had chunked down to 250MB 7z files. From SBS 2011 to Mac and wanted to check they arrived OK.

This script creates an md5sum formatted file. The only caveat is you have to convert it to Unix line ends when you get it to the Mac box.

I use brew to install dos2unix and have gmd5sum on the mac laptop.

So after using this power shell script on the windows box to generate the md5sum.txt file

$files = @(Get-ChildItem "*.7z.*" -Name)

foreach( $filename in $files) {
	$someFilePath = $filename
	$md5 = New-Object -TypeName System.Security.Cryptography.MD5CryptoServiceProvider
	$hash = [System.BitConverter]::ToString($md5.ComputeHash([System.IO.File]::ReadAllBytes($someFilePath)))
	$outfile =  $hash.replace("-","").Trim() + "  " + $filename.Trim() 
	echo $outfile

You need to run it like this:

E:\admin\mailbox_exports\complete>powershell -command "./filehash.ps1" > md5sum.txt

On the mac box I used the dos2unix utility to convert the file and then gmd5sum to check the files md5sum

$ dos2unix md5sum.txt 
$ dos2unix: converting file md5sum.txt to Unix format...
$ gmd5sum -c md5sum.txt
accounts20150826.7z.001: OK
accounts20150826.7z.002: OK
accounts20150826.7z.003: OK
accounts20150826.7z.004: OK
mcph20150826.7z.001: OK
mcph20150826.7z.002: OK
mcph20150826.7z.003: OK
mona20150826.7z.001: OK
mona20150826.7z.002: OK
mona20150826.7z.003: OK
mona20150826.7z.004: OK
mona20150826.7z.005: OK

$ dos2unix --version
dos2unix 7.2.3 (2015-07-01)
With Unicode UTF-16 support.
Without native language support.


Submit a Comment

Your email address will not be published. Required fields are marked *

This site is protected by reCAPTCHA and the Google Privacy Policy and Terms of Service apply.

The reCAPTCHA verification period has expired. Please reload the page.

You May Also Like…