Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- $destination = "YourDestination"
- $name = "MovedDoubles_temp"
- if(Test-path $destination\$name){Write-host "Temp folder already created"}
- else
- {New-Item "$destination\$name" -ItemType Directory}
- $allfileshash = gci $destination -recurse | Get-FileHash | Group-Object -Property hash
- $doubles = $allfileshash | where {$_.Count -gt 1}
- foreach($double in $doubles)
- {
- $FilesToMove = $double.group.path
- foreach($FileToMove in $FilesToMove)
- {Move-Item -Path $filetomove -Destination "$destination\$name"}
- $FilesInTemp = GCI "$destination\$name"
- $filecount = $FilesInTemp.count -1
- $filesintemp | sort CreationTime -Descending | select -Last $filecount | remove-item
- GCI "$destination\$name" | Move-Item -Destination $destination
- }
- Remove-Item $destination\$name
Advertisement
Add Comment
Please, Sign In to add comment