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.

WindowshashFilesduplicatespowershellLow risk
Pipe Get-ChildItem -Recurse -File into Get-FileHash, then Group-Object Hash and keep groups with a Count greater than 1.

01Command

Command
$ $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 -AutoSize

02What 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

RiskLow risk
!Warning: Hashing a large folder can take minutes and 100% disk/CPU; run it on a specific folder rather than the whole drive.

04Undo

✓No undo needed — this command does not change persistent state.

05Sources

  • Get-FileHash
    Microsoft Learn · vendor-doc · 2026-09-17
    Evidence: Get-FileHash computes the SHA256 hash of files piped in, so identical files produce identical hashes that can be grouped.
  • Get-FileHash - SS64
    SS64 · technical · 2026-09-17
    Evidence: 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