Advertisement
guyrleech

Get File Hashes for all files & find duplicates

Jan 26th, 2024 (edited)
1,022
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. ## Find files in folders starting in the current folder that match the name & create csv with file properties, SHA256 checksum & file size in MB (which is easier to read than bytes)
  2. ## Use to help find duplicate files which will have the same hash
  3.  
  4. ls *folderpattern* -force -Recurse | Where { -Not $_.PSIsContainer -and $_.Length -ge 100MB } | select *,@{n='Size (MB)';e={ [math]::round( $_.Length / 1MB , 1 ) }},@{n='Hash';e={Get-FileHash $_.FullName -EA continue|select -expand Hash}} -exclude PS* | export-csv -NoTypeInformation .\files.and.hashes.csv
  5.  
  6. ## Import hashes back into PowerShell object
  7. $hashes = import-csv .\files.and.hashes.csv
  8.  
  9. ## Group by hash so we find files (>100MB) which are the same/duplicate
  10. $hashes|where { -Not [string]::IsNullOrEmpty( $_.Hash ) }|select fullname,hash|group hash|where count -gt 1|sort count -desc|select count,@{n='File';e={($_.group|select -expand fullname) -join "`n"}}|ft -AutoSize -wrap
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement