Group duplicate files by SHA-256 hash in PowerShell
Build a paste-ready command, then review its compatibility and effects before running it.
Get-ChildItem <folder> -File -Recurse | Get-FileHash -Algorithm SHA256 | Group-Object Hash | Where-Object Count -gt 1 | ForEach-Object GroupComplete required fields to copy the generated command.
read-onlyno known side effects Compatibility
WindowsVerified for Windows using powershell syntax.
Operational knowledgereview due 2027-01-19
RequirementsGet-ChildItemGet-ChildItem must be installed and available on PATH.
Version supportGet-ChildItem Current supported releasesVerified for windows using powershell syntax; consult compatibility notes for platform-specific differences.
Expected signalsAlgorithm Hash PathRepresentative successful output; values vary with the selected target and system state.
Known errorsGet-ChildItem: command not foundGet-ChildItem is missing or is not available on PATH.
VerifyGet-ChildItem {{folder}} -File -Recurse | Get-FileHash -Algorithm SHA256 | Group-Object Hash | Where-Object Count -gt 1 | ForEach-Object GroupThe output matches the expected target and exits without an error.Rollback noteNot required: this command is read-only and does not change system state.
Command breakdown
01Get-ChildItemCommandRuns the Get-ChildItem stage of this one-liner.
02<folder>ParameterA value supplied in the Fill parameters section.
03-FileOptionConfigures Get-ChildItem with the -File option.
04-RecurseOptionConfigures Get-ChildItem with the -Recurse option.
05|PipelinePasses the output on the left to the command on the right.
06Get-FileHashCommandRuns the Get-FileHash stage of this one-liner.
07-AlgorithmOptionConfigures Get-FileHash with the -Algorithm option.
08SHA256ArgumentPasses SHA256 to Get-FileHash.
09|PipelinePasses the output on the left to the command on the right.
10Group-ObjectCommandRuns the Group-Object stage of this one-liner.
11HashArgumentPasses Hash to Group-Object.
12|PipelinePasses the output on the left to the command on the right.
13Where-ObjectCommandRuns the Where-Object stage of this one-liner.
14CountArgumentPasses Count to Where-Object.
15-gtOptionConfigures Where-Object with the -gt option.
161ArgumentPasses 1 to Where-Object.
17|PipelinePasses the output on the left to the command on the right.
18ForEach-ObjectCommandRuns the ForEach-Object stage of this one-liner.
19GroupArgumentPasses Group to ForEach-Object.
This advanced community-curated one-liner combines several stages. Review every option and placeholder before running it.
Example input
Get-ChildItem .\photos -File -Recurse | Get-FileHash -Algorithm SHA256 | Group-Object Hash | Where-Object Count -gt 1 | ForEach-Object Group
Example output
Algorithm Hash Path
--------- ---- ----
SHA256 8D969EEF6ECAD3C29A3A629280E686CF0C3F5D5A86AFF3CA12020C923ADC6C92 C:\photos\copy.jpg
SHA256 8D969EEF6ECAD3C29A3A629280E686CF0C3F5D5A86AFF3CA12020C923ADC6C92 C:\photos\original.jpg
Illustrative output — exact values vary by system and data.
Official sources