How do I find duplicate files by hash on Windows?
Use PowerShell to group files by SHA256 and confirm identical copies before you delete anything.
What this covers
Duplicate photos, downloads and documents can silently eat disk space on Windows. Hashing each file and grouping equal hashes is the reliable way to find true duplicates, not just files with the same name. This guide uses built-in PowerShell and cmd tools, so there is nothing extra to install.
Symptom
See where the space is going
Start by listing the largest files in your user folder. This tells you which folders are worth scanning for duplicates, so you do not hash an entire drive unnecessarily. Replace the sample path with your own top-level folder. If the largest files are all in one project or photo folder, that is the folder to scan next. Worked if you have a short list of big files and their full paths.
Recursively list files sorted by size, largest first, to hunt down disk-space hogs in any directory tree.
$ Get-ChildItem -Path C:\Users\me -Recurse -File | Sort-Object Length -Descending | Select-Object -First 20 Length, FullNameGroup files by SHA256 to find duplicates
This is the core step: PowerShell hashes every file under the folder you choose and groups files that share the same hash. Replace the sample path with the folder from the previous step or the folder you suspect. The output shows each duplicate group with the full path and hash. Worked if you see groups with Count greater than 1; files in the same group are identical by content. Review each group and decide which copy to keep, but do not delete yet.
Group duplicate files by SHA256 hash with Get-FileHash and Group-Object to clean up copied photos and documents on Windows.
$ $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 -AutoSizeConfirm a pair byte-for-byte before deleting
Pick one duplicate group from the previous step and use the built-in byte-for-byte compare on the two full paths you are checking. Replace the sample file names with the exact paths from the duplicate group. This byte-level check catches any path mix-up and confirms the files are truly identical. Worked if the compare reports no differences. Once you see that, delete the extra copy and keep the one you chose.
The built-in file compare tool reports whether two text or binary files differ and shows every mismatching byte with its hex offset.
$ fc /b file1.bin file2.binHow to confirm it worked
You should see one or more groups where every file shares the same SHA256 hash. After you remove the extra copies, rerun the grouping and the duplicate count should drop to zero for those folders.
Sources
- Get-ChildItem | Microsoft LearnEvidence: Microsoft documents Get-ChildItem with -Recurse and -File, and that FileInfo objects expose the Length property, which can be sorted with Sort-Object.
- Get-ChildItem - PowerShellEvidence: SS64 shows Get-ChildItem piped into Sort-Object and Select-Object to rank files, e.g. by file size.
- 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.
- fc | Microsoft LearnEvidence: Microsoft documents fc /b as performing a binary comparison, displaying every differing byte with its offset.
- File Compare - fc - Windows CMDEvidence: SS64 lists fc switches including /b for binary comparison, /c to ignore letter case, and /n to show line numbers in ASCII mode.
Last verified: 2026-09-22
Related guides
Use forfiles to preview old files, clear %TEMP% with PowerShell, and confirm space is back with Disk Cleanup.
Control what runs when Windows starts: open the Startup folder, change service startup types, and handle Fast Startup quirks.
Check your Windows drives' hardware health, scan for file system errors, and schedule a repair — all from PowerShell and the command prompt.