Last active
October 4, 2017 06:36
-
-
Save kennwhite/ea5c371ed784bf68ab3f to your computer and use it in GitHub Desktop.
Simple Win7/8 PowerShell script to compute md5, sha, and sha256 hash for a file
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Simple powershell (built-in to Win7/8) utility script | |
# to compute sha256 (or md5, sha1 or sha512) of a file | |
# | |
# Usage: | |
# C:\> powershell | |
# PS .\hash filename.ext [sha|md5|sha256|sha512] | |
# | |
# May require: Control Panel/System/Admin/Windows Power Shell Modules, then: set-executionpolicy remotesigned | |
# | |
# Based on James Manning's and Mike Wilbur's get-hashes and get-sha256 MSDN scripts | |
# | |
param( | |
[string] $file = $(throw "A filename is required. Usage: .\hash filename.ext [sha|md5|sha256|sha512]"), | |
[string] $algorithm = 'sha256' | |
) | |
$fileStream = [system.io.file]::openread((resolve-path $file)) | |
$hasher = [System.Security.Cryptography.HashAlgorithm]::create($algorithm) | |
$hash = $hasher.ComputeHash($fileStream) | |
$fileStream.close() | |
$fileStream.dispose() | |
[system.bitconverter]::tostring($hash).ToLower().replace('-','')+" '"+$file+"' "+$algorithm+"`r`n" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment