r/PowerShell • u/DiskBytes • Dec 07 '25
Question sha256 with Powershell - comparing all files
Hello, if I use
Get-ChildItem "." -File -Recurse -Name | Foreach-Object { Get-FileHash -Path $($_) -Algorithm SHA256 } | Format-Table -AutoSize | Out-File -FilePath sha256.txt -Width 300I can get the checksums of all files in a folder and have them saved to a text file. I've been playing around with it, but I can't seem to find a way where I could automate the process of then verifying the checksums of all of those files again, against the checksums saved in the text file. Wondering if anyone can give me some pointers, thanks.
13
Upvotes
View all comments
Show parent comment
0
u/Sea_Ice6776 Dec 08 '25 edited Dec 11 '25
This is factually and demonstrably false, even on old-ish hardware. SHA256 is significantly faster than MD5 and even SHA1, and the gains are linearly proportional to input size. Depending on the CPU and the .net/PS version in use, SHA512 can be even faster, too. The only cost is the size of the hashes, which is pretty insignificant anyway.
Get-FileHash, if given a wildcard path, already gives you an object. Just select out the Path and Hash properties into your JSON/CSV/whatever, and use that for future comparisons.
Here's proof of #1 for you:
On my machine, which has an older AMD Ryzen 7 5800X CPU (4 generations old at this point) SHA256 is a little more than twice as fast as SHA1, and SHA512 had the same runtime within less than 1%.
And this is single-threaded performance with the only difference being the hash algorithm.
SHA256 is not overkill.
Whoops. I didn't include MD5 in the above originally. Added now.
It consistently takes about 20% longer than SHA1 on my system, making it the worst of the bunch.
A non-trivial part of that is because the wider algorithms are processing larger chunks of data at once.