Skip to content

Instantly share code, notes, and snippets.

@tuantmb
Created October 21, 2023 09:16
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save tuantmb/21c4e04c51ea920b8d009988557d44d4 to your computer and use it in GitHub Desktop.
Save tuantmb/21c4e04c51ea920b8d009988557d44d4 to your computer and use it in GitHub Desktop.
Powershell to list duplicate files in current directory
Get-ChildItem * -Recurse | Get-FileHash -Algorithm MD5 | Group-Object hash | Where-Object {$_.Count -gt 1} | Select-Object @{n='DupeCount';e={$_.Count}}, @{n='DupeFiles';e={$_.Group.Path -join [System.Environment]::NewLine}}, @{n='Hash';e={$_.Name}} | Out-GridView
@tuantmb
Copy link
Author

tuantmb commented Oct 21, 2023

Get-ChildItem -Recurse | Get-FileHash | Group-Object -Property Hash | Where-Object { $_.Count -gt 1 } | foreach {
    $group = $_.Group | Select-Object -ExpandProperty Path
    $group | Select-Object -Skip 1 | Remove-Item -Force
}

@tuantmb
Copy link
Author

tuantmb commented Oct 21, 2023

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment