Skip to content

Instantly share code, notes, and snippets.

@Announcement
Created July 15, 2025 23:35
Show Gist options
  • Save Announcement/3fa92b1cd3eb6f5323c4e774d4f5fb8c to your computer and use it in GitHub Desktop.
Save Announcement/3fa92b1cd3eb6f5323c4e774d4f5fb8c to your computer and use it in GitHub Desktop.
$Downloads = (Get-Content Env:\USERPROFILE | Get-Item).GetDirectories('Downloads').GetFiles() | ForEach-Object -Parallel { $_ | Add-Member -NotePropertyName Hash -NotePropertyValue (Get-FileHash -LiteralPath $_.FullName) -PassThru }
$Downloads | Group @{Expression={$_.hash.Hash}} | Where Count -GT 1 | ForEach-Object -Parallel { [System.IO.FileInfo[]]$Group = Select -InputObject $PSItem -ExpandProperty Group | Sort CreationTime; $Primary = $Group[0]; $Duplicates = $Group | Select -Skip 1; $Recovery = [int]($Duplicates | Measure-Object -Property Length -Sum | Select -Expand Sum); ([string]$Primary.Length).PadLeft(10).PadRight(12) + $Primary.Name + "`n" + ( $Duplicates | % { ''.PadRight(12) + $_.Name + "`n" } ) | Write-Host ; $Duplicates | Write-Output } | Tee-Object -Variable Duplicates | Measure-Object -Sum -Property Length | Select-Object -ExpandProperty Sum | % { [int]($_) } | Set-Variable -Name Junk ; "".PadRight(12) + "Duplicates`n" + ([string]$Junk).PadLeft(10).PadRight(12) + ($Duplicates.Name | Join-String -Separator "`n " ) | Write-Output ; $Duplicates | Remove-Item -Confirm
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment