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

**URL:** <https://forums.powershell.org/t/create-hash-file-of-directory-then-compare-with-same-directory/20964>\
**Category:** PowerShell Help\
**Created:** [November 18, 2022, 9:45pm UTC](https://forums.powershell.org/t/create-hash-file-of-directory-then-compare-with-same-directory/20964 "2022-11-18T21:45:25Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![corhsin](https://sea1.discourse-cdn.com/flex019/user_avatar/forums.powershell.org/corhsin/32/4105_2.png) [@corhsin](https://forums.powershell.org/u/corhsin)\
**Post date:** [November 18, 2022, 9:45pm UTC](https://forums.powershell.org/t/create-hash-file-of-directory-then-compare-with-same-directory/20964/1 "2022-11-18T21:45:25Z")

</div>

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](https://us1.discourse-cdn.com/flex019/uploads/powershell/original/2X/1/19d5e1d8989c5a3821e771370e9052ce349fad4f.png)

---

<div class="post-metadata">

**Author:** ![neemobeer](https://sea1.discourse-cdn.com/flex019/user_avatar/forums.powershell.org/neemobeer/32/4087_2.png) [@neemobeer](https://forums.powershell.org/u/neemobeer)\
**Post date:** [November 19, 2022, 12:31am UTC](https://forums.powershell.org/t/create-hash-file-of-directory-then-compare-with-same-directory/20964/2 "2022-11-19T00:31:47Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![corhsin](https://sea1.discourse-cdn.com/flex019/user_avatar/forums.powershell.org/corhsin/32/4105_2.png) [@corhsin](https://forums.powershell.org/u/corhsin)\
**Post date:** [November 19, 2022, 5:00pm UTC](https://forums.powershell.org/t/create-hash-file-of-directory-then-compare-with-same-directory/20964/3 "2022-11-19T17:00:40Z")

</div>

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. ` `
5. ` $allFiles = foreach($folder in $folders) {`
6. ` Get-Childitem -path $folder -recurse |`
7. ` select FullName,Name,Length,CreationTime,LastWriteTime |`
8. ` foreach {`
9. ` $hash = Get-FileHash $_.FullName`
10. ` add-member -InputObject $_ -NotePropertyName Hash -NotePropertyValue $hash.Hash`
11. ` add-member -InputObject $_ -NotePropertyName RelativePath -NotePropertyValue $_.FullName.Replace($folder, '') -PassThru `
12. ` }`
13. ` }`
14. ` `
15. ` $allFiles | select -First 10 | ft RelativePath, Hash`

---

<div class="post-metadata">

**Author:** ![krzydoug](https://sea1.discourse-cdn.com/flex019/user_avatar/forums.powershell.org/krzydoug/32/1008_2.png) [@krzydoug](https://forums.powershell.org/u/krzydoug)\
**Post date:** [November 19, 2022, 6:47pm UTC](https://forums.powershell.org/t/create-hash-file-of-directory-then-compare-with-same-directory/20964/4 "2022-11-19T18:47:37Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![dotnVo](https://avatars.discourse-cdn.com/v4/letter/d/4af34b/32.png) [@dotnVo](https://forums.powershell.org/u/dotnVo)\
**Post date:** [May 16, 2024, 8:16pm UTC](https://forums.powershell.org/t/create-hash-file-of-directory-then-compare-with-same-directory/20964/5 "2024-05-16T20:16:21Z")

</div>


