Created
July 15, 2025 23:35
-
-
Save Announcement/3fa92b1cd3eb6f5323c4e774d4f5fb8c to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
$Downloads = (Get-Content Env:\USERPROFILE | Get-Item).GetDirectories('Downloads').GetFiles() | ForEach-Object -Parallel { $_ | Add-Member -NotePropertyName Hash -NotePropertyValue (Get-FileHash -LiteralPath $_.FullName) -PassThru } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
$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