Home > Powershell, Windows > Get an MD5 or SHA1 Checksum with PowerShell

Get an MD5 or SHA1 Checksum with PowerShell

September 14th, 2011 Leave a comment Go to comments

I was excited about the Windows 8 developer preview that was released earlier tonight, so I fired up Virtual PC to start playing around with it.  I ended up with an error when it was loading so I thought maybe I had a bad copy of the ISO so I thought "I know, I'll do a checksum test."  Unfortunately, I don't have a tool to take a checksum on my current machine so naturally I wrote a simple function in PowerShell to do the checksum test for me.

It has only a few simple parameters that you can enter, file and algorithm.  "File" is for the actual file you want to checksum.  "Algorithm" is either "sha1" or "md5" and will let you get both an MD5 and a SHA1 checksum of the specified file.

Update: If you came here looking for the SHA1/MD5 hashes for the Windows 8 CTP iso’s, here you go.

Windows Developer Preview with developer tools English, 64-bit (x64)
SHA1: 6FE9352FB59F6D0789AF35D1001BD4E4E81E42AF
MD5: 116EB08542BB48FE4314BB6DEA39335E

Windows Developer Preview English, 64-bit (x64)
SHA1: 79DBF235FD49F5C1C8F8C04E24BDE6E1D04DA1E9
MD5: DFCB53C7B32351784C37E5DE0A7B1167

Windows Developer Preview English, 32-bit (x86)
SHA1: 4E0698BBABE01ED27582C9FC16AD21C4422913CC
MD5: 9B7798438FA694ECFA465C93A4C23C97


You can download the full script after the jump.

function Get-Checksum
    Param (
        [string]$File=$(throw("You must specify a filename to get the checksum of.")),

    $fs = new-object System.IO.FileStream $File, "Open"
    $algo = [type]"System.Security.Cryptography.$Algorithm"
	$crypto = $algo::Create()
    $hash = [BitConverter]::ToString($crypto.ComputeHash($fs)).Replace("-", "")

Categories: Powershell, Windows Tags: , , , ,
  1. September 9th, 2013 at 15:14 | #1

    Nice little function, Tom. I think I stumbled upon this a little while back before I even realized this was your site!

    To avoid any read-only file issues you should create the file stream object with read access.
    $fs = new-object System.IO.FileStream $File, “Open”, “Read”, “Read”;

  1. April 18th, 2014 at 04:41 | #1
  2. April 18th, 2014 at 04:42 | #2
  3. April 28th, 2014 at 04:07 | #3
You must be logged in to post a comment.