Skip to content

Instantly share code, notes, and snippets.

@JamesDBartlett3
Created November 18, 2021 18:26
Show Gist options
  • Save JamesDBartlett3/07e393d7adf320b6fbbaef973e31290d to your computer and use it in GitHub Desktop.
Save JamesDBartlett3/07e393d7adf320b6fbbaef973e31290d to your computer and use it in GitHub Desktop.
Get-FolderHash -- a PowerShell function for computing the SHA1 hash of an entire folder's contents
# Source: https://social.technet.microsoft.com/Forums/en-US/2e7db624-2260-4a65-a57b-f6f2e22312f0/sha1-hash-of-an-entire-folder-structure
Function Get-FolderHash ($folder) {
Get-ChildItem $folder -Recurse |
Where-Object {!$_.psiscontainer} |
ForEach-Object {[Byte[]]$contents += [System.IO.File]::ReadAllBytes($_.fullname)}
$hasher = [System.Security.Cryptography.SHA1]::Create()
[string]::Join("",$($hasher.ComputeHash($contents) | ForEach-Object {"{0:x2}" -f $_}))
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment