Alon_EH
Alon_EH

Reputation: 21

Same file, different hashes with PowerShell Get-FileHash command

I'm trying to write a PowerShell script that will copy image files from one folder to another, but only if the files don't already exist in the destination folder.
The files are randomly named.

The issue is that Get-FileHash keeps returning different hashes even when the files are identical.

For the sake of simplicity, I produced the following scenario:
I have 2 JPG files, which are the same image.

However, PowerShell gives them different hashes:

$oldFileHash = Get-FileHash .\image1.jpg  -Algorithm "SHA256"
>> $newFileHash = Get-FileHash .\temp\image2.jpg -Algorithm "SHA256"
>>
>> $oldFileHash.Hash
>> $newFileHash.Hash
21CE9E2CE18AC46DF13400C4CEFA11FB254D96E9D39BD67FA2F4189ACF4F5D3B
6441924D9D2349D3CFD8164B18DF8DA2FFA9F281DE198E56C0AE4CFDBFBCE8AD

I tried using MD5 algorithm instead of SHA256, and got the different hashes as well.

What would cause this behavior?

Upvotes: 1

Views: 1147

Answers (1)

Alon_EH
Alon_EH

Reputation: 21

As zett42 suggested, this must have been a test error.
I've deleted contents of both folders and started over, and my script worked as expected

Upvotes: 1

Related Questions