Create .hash file of directory, then compare with same directory

The goal is to hash all files in a directory /s, output the hashes to a file, then use that file to compare hashes to a directory in another location. Can this be accomplished? Many utilities such as QuickSFV (old, not fully functional) or OpenHashTab can do this. It should be an option. Suggestions? Example photo included. TIA
Hashing_with_a_dot-hash_file

You can use
Get-ChildItem, a for each loop and Get-FileHash

That is a good start :). Can you provide some detail? Which hashing do you recommend? My limited understanding is Powershell Get-FileHash is functional, and ‘CertUtil’ is an alternative. It is appreciated.

Edit: This creates the CSV. From there, how is it utilized to check against an alternate directory?

  1. param (
  2. $folders = @("C:\temp_fotos\", "C:\fotos_temp\") #case sensitive
  3. )
  4. $allFiles = foreach($folder in $folders) {
  5. Get-Childitem -path $folder -recurse |
  6. select FullName,Name,Length,CreationTime,LastWriteTime |
  7. foreach {
  8. $hash = Get-FileHash $_.FullName
  9. add-member -InputObject $_ -NotePropertyName Hash -NotePropertyValue $hash.Hash
  10. add-member -InputObject $_ -NotePropertyName RelativePath -NotePropertyValue $_.FullName.Replace($folder, '') -PassThru
  11. }
  12. }
  13. $allFiles | select -First 10 | ft RelativePath, Hash

It sounded like homework originally and now with the numbered commands I’m feeling stronger about that. Either way, you should know this forum is for helping users with issues they are facing with their code. It is not a script factory. If you have a specific point where you’ve hit a roadblock, please share that.

1 Like