Using Powershell for MD5 Checksums

The older I get, the more paranoid I get about things I download. Today I downloaded a freeware program from a 3rd party download site, since the publisher doesn’t actually allow downloading from their site. All they give is an MD5 checksum.

Well, I decided to write a quick Powershell script to do the checksum for me. (Got some pointers from another blog writing a cmd-let to do the same thing)


$algo = [System.Security.Cryptography.HashAlgorithm]::Create("MD5")
$stream = New-Object System.IO.FileStream($file, [System.IO.FileMode]::Open)

$md5StringBuilder = New-Object System.Text.StringBuilder
$algo.ComputeHash($stream) | % { [void] $md5StringBuilder.Append($_.ToString("x2")) }


I probably should add a try/catch for the stream disposal and file existence validation. But, you get the picture.