I can never remember where (or the name of) the random .EXE that I usually keep around for calculating SHA1 hashes is, and it seemed silly not to just spend the 10 minutes to write it in PowerShell. After all, everything you need is in .NET, right?
param([switch]$csv, [switch]$recurse) [Reflection.Assembly]::LoadWithPartialName("System.Security") | out-null $sha1 = new-Object System.Security.Cryptography.SHA1Managed $pathLength = (get-location).Path.Length + 1 $args | %{ if ($recurse) { $files = get-childitem -recurse -include $_ } else { $files = get-childitem -include $_ } if ($files.Count -gt 0) { $files | %{ $filename = $_.FullName $filenameDisplay = $filename.Substring($pathLength) if ($csv) { write-host -NoNewLine ($filenameDisplay + ",") } else { write-host $filenameDisplay } $file = [System.IO.File]::Open($filename, "open", "read") $sha1.ComputeHash($file) | %{ write-host -NoNewLine $_.ToString("x2") } $file.Dispose() write-host if ($csv -eq $false) { write-host } } } }