Find Duplicate Files by Hash in PowerShell
Group duplicate files by SHA256 hash with Get-FileHash and Group-Object to clean up copied photos and documents on Windows.
01Command
$ $files = Get-ChildItem 'C:\Users\me\Pictures' -Recurse -File
$files | Get-FileHash -Algorithm SHA256 |
Group-Object Hash | Where-Object Count -gt 1 |
ForEach-Object { $_.Group | Select-Object Path, Hash } | Format-Table -AutoSize02What it does
Two files can have the same name and size without being identical, but the SHA256 hash matches only when the content is byte-for-byte the same. Grouping by Hash collapses every copy of a file into one entry; any group with more than one member is a duplicate set. Delete extras after spot-checking a couple of groups, because files that happen to be identical on purpose (empty placeholders, license files) will also appear.
03Risk
04Undo
✓No undo needed — this command does not change persistent state.
05Sources
- Get-FileHashEvidence: Get-FileHash computes the SHA256 hash of files piped in, so identical files produce identical hashes that can be grouped.
- Get-FileHash - SS64Evidence: Get-FileHash accepts pipeline input of FileInfo objects and supports SHA256 as the default algorithm.
Last verified: 2026-09-18 · Category: Files & Folders
06Related solutions
Diagnose NTFS file system errors and bad sectors on any volume — including the system drive while Windows is running — before committing to a repair.
Robocopy is Windows' built-in robust file copier: use /MIR to keep a destination folder as an exact one-way mirror of a source, resumable and restartable.
Search inside text files and logs with regex, returning file, line number and match.