Skip to content

Instantly share code, notes, and snippets.

@mitchelldavis
Last active August 29, 2015 14:03
Show Gist options
  • Save mitchelldavis/33570d3d31df70a76f9d to your computer and use it in GitHub Desktop.
Save mitchelldavis/33570d3d31df70a76f9d to your computer and use it in GitHub Desktop.
Get SHA256 hash of a file.
param(
[string] $file = $(throw 'a filename is required'),
[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).Replace("-","").ToLower()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment