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
4
u/BlackV Dec 07 '25 edited Dec 08 '25
the
format-*cmdlets are really for screen out out onlyyou are doing extra work that is unneeded
if you export to a useful format like csv you can import that same info back in
as an example to break it down into bits
now you have a CSV, if you want that to be human readable, use tab
"`t"as the delimiterYou can import using
if you then looped your imported hashes you could get the current hash again
then you could compare those 2 values
$Updated.Hashand$SingleFile.hash\probably more efficient (and you're reusing your code) is to get all the hashes again with your original command and compare the to objects
7
u/arpan3t Dec 07 '25
1
u/_RemyLeBeau_ Dec 08 '25
Have your script run and save to a file. When you run the script again, have the results save into a different file. You can then compare checksums of each saved file against each other. If they're the same, the checksums will match.
2
u/Snickasaurus Dec 07 '25
Might be easier to do what you're looking for if you write to a CSV instead of a plain text file. If you can take the code below or parts of it that you want, you should be able to run the script again in the future and validate with another script.
1
u/Adam_Kearn Dec 07 '25
If I was going to do something like this then I would get the full-file-path and the date created and convert this into base64
You can then store this within a key-value JSON file/database. With the value being the SHA.
You can then run your script on this folder and check each value compared with your known values.
26
u/[deleted] Dec 08 '25
[removed] — view removed comment