ContextCleaner: see every entry in the Windows 11 right-click menu, and which app added it — on the Microsoft Store.
Engineering DupeDoctor

How to Find Duplicate Files with PowerShell Using Get-FileHash

Published October 23, 2026 Updated October 23, 2026 8 min read

To find duplicate files with PowerShell, list the files with Get-ChildItem, hash each one with Get-FileHash, then use Group-Object on the Hash property and keep the groups with more than one file. Files with identical hashes have identical content, even if their names differ. The script below does this, and grouping by size first makes it much faster. If you would rather review duplicate sets visually and remove copies to the Recycle Bin, DupeDoctor from Automata Labs does the same content check, plus look-alike photos, in one offline scan.

Find exact and look-alike duplicates without writing a script, and recycle only what you choose.

Get it from Microsoft

How does Get-FileHash detect duplicate files?

Microsoft’s Get-FileHash documentation explains that you can “use hash values to determine if two different files have exactly the same content. If the hash values of two files are identical, the contents of the files are also identical.”

The cmdlet uses SHA256 unless you choose otherwise, and also accepts SHA1, SHA384, SHA512 and MD5. Microsoft notes that MD5 and SHA1 “are no longer considered secure” and should only be used for simple change validation. For finding duplicates on your own drive, SHA256 is a safe default.

Group-Object then does the matching. It groups objects that have the same value for a property, and each group has a Count. Any hash group with a Count above 1 is a set of duplicates.

What is the basic PowerShell script to find duplicates?

Open PowerShell and change the path to the folder you want to check:

Get-ChildItem -Path 'D:\Photos' -File -Recurse |
    Get-FileHash -Algorithm SHA256 |
    Group-Object -Property Hash |
    Where-Object Count -gt 1 |
    ForEach-Object { $_.Group | Select-Object Hash, Path }

What each line does:

  1. Get-ChildItem -File -Recurse lists every file in the folder and its subfolders, skipping folders themselves.
  2. Get-FileHash reads each file and computes its SHA256 hash. It accepts the files from the pipeline through its LiteralPath parameter.
  3. Group-Object -Property Hash puts files with the same hash together.
  4. Where-Object Count -gt 1 keeps only groups with at least two files.
  5. The last line prints each duplicate’s hash and full path.

To save the results for review in a spreadsheet, replace the last line with an export:

    ForEach-Object { $_.Group } |
    Select-Object Hash, Path |
    Export-Csv -Path "$env:USERPROFILE\Desktop\duplicates.csv" -NoTypeInformation

How can I make the duplicate search faster?

The basic script hashes every file, which means reading every byte on the drive. Two files can only be identical if they are the same size, so group by size first and hash only the files that share a size with another file:

Get-ChildItem -Path 'D:\Photos' -File -Recurse |
    Group-Object -Property Length |
    Where-Object Count -gt 1 |
    ForEach-Object { $_.Group } |
    Get-FileHash -Algorithm SHA256 |
    Group-Object -Property Hash |
    Where-Object Count -gt 1 |
    ForEach-Object { $_.Group | Select-Object Hash, Path }

On a folder of photos or documents, most files have a unique size, so this skips most of the hashing. It is the same idea dedicated duplicate finders use.

Why do two identical-looking files have different hashes?

A hash changes if even one byte changes, so files that look the same to you can still hash differently. Common reasons:

  • Edited metadata. Adding a rating, tag or caption to a photo, or a title to a song, rewrites part of the file. The picture or audio is unchanged, but the bytes are not.
  • Re-saving or exporting. Opening a JPEG and saving it again re-encodes the image, even at the same size and quality setting.
  • Different formats. The same photo saved as PNG and as JPEG is stored completely differently.
  • Downloads and sync tools. A second download of the same document can carry different embedded data, depending on how the site generated it.

In all of these cases a hash script will report no duplicates, which is correct for byte-level copies but not what most people mean by “the same photo.” That is the gap perceptual matching fills: it compares what an image looks like rather than how it is stored, so you should always review those matches before removing anything.

What are the limits of the PowerShell method?

The script is accurate for exact copies, but it is a finding tool, not a cleanup tool. The practical gaps:

NeedPowerShell scriptDupeDoctor
Exact duplicates by contentYes, SHA256Yes, size grouping then BLAKE3 hash
Renamed copiesYesYes
Look-alike photos at other sizes or formatsNoYes, perceptual hashing
Similar videos and songsNoYes, according to its listing
Visual review with thumbnailsNo, text or CSV onlyYes, plus side-by-side compare
Keep-one safety ruleUp to youAt least one file per set always kept
DeletingRemove-Item, no Recycle BinRecycle Bin only, or move, or hardlink
Protecting system foldersUp to youWindows system locations never touched
Report exportExport-CsvCSV or JSON

The biggest risk is the delete step. Remove-Item does not send files to the Recycle Bin, and a one-line “delete everything after the first file” command can remove the copy you meant to keep, such as the one in your organized folder rather than the one in Downloads. Hashing a large drive can also take a long time, and files that cannot be read will show errors instead of hashes.

If you do delete with a script, test it with -WhatIf first, and decide which path to keep in each set, not just which file came first. Our guide to safely removing duplicate files on Windows 11 covers a careful process.

Review duplicate sets with thumbnails and recycle extras safely, with one file always kept.

Get it from Microsoft

How does DupeDoctor compare to a hash script?

DupeDoctor uses the same principle, content not names, with a safer workflow around it. According to its Microsoft Store listing:

  • Content-verified exact duplicates: size grouping prunes non-matches, then BLAKE3 hashing confirms byte-for-byte copies, so renamed files are caught.
  • Look-alike photos found with perceptual hashing, including different sizes, crops and formats, with a Strict-to-Loose slider and an option to match rotated and flipped shots.
  • Similar videos and duplicate songs across re-encodes, bitrates and formats.
  • Copy-named clutter such as “file (1)” and “file (2)” grouped per folder.
  • Auto-keep rules to keep the newest, oldest or shortest path in exact and copy-named sets, with undo. Look-alike matches are never auto-selected.
  • Recycle Bin only deletion, with no permanent-delete path, and at least one file in every set always kept.
  • Alternatives to deleting: move extras to a folder, or replace exact copies with hardlinks.
  • Export of everything found as CSV or JSON.
  • 100% offline, with no network client, no telemetry and no account.

A persistent scan cache also remembers hashes for unchanged files, so repeat scans are faster, which is hard to match with a script you rerun from scratch.

Frequently asked questions

Can Get-FileHash find duplicate photos that were resized?

No. A resized or re-encoded photo has different bytes and a different hash. You need perceptual matching, which compares how images look.

Is MD5 good enough for finding duplicates?

For your own files, MD5 usually works, but Microsoft recommends against MD5 and SHA1 for anything that needs protection from tampering. SHA256 is the default and a safe choice.

How do I find duplicates across two drives?

Pass both paths to Get-ChildItem, for example -Path 'D:\Photos','E:\Backup'. For a fuller method, see finding duplicates across backup drives.

How do I check one file’s hash in Command Prompt?

Use certutil. Our guide to verifying a SHA256 hash with certutil shows the command.

Does DupeDoctor delete files permanently?

No. According to its listing, deletion always goes to the Windows Recycle Bin, so removed files can be restored.

Try DupeDoctor

Get DupeDoctor from the Microsoft Store. It is a one-time purchase with no subscription, and the Store listing shows the current price.

Reclaim disk space from duplicates in one offline scan, with every deletion recoverable.

Get it from Microsoft

Microsoft, Windows and PowerShell are trademarks of the Microsoft group of companies. DupeDoctor is not affiliated with or endorsed by Microsoft.

Last updated 23 October 2026. Published by Automata Labs, a software company in Canada.

// release_radar

Get notified about new releases.

We build native, local-first tools for professionals who refuse SaaS fatigue. Drop your email to hear about new apps, major updates, and zero-telemetry releases as they land on the Microsoft Store. No spam — just release news.