Old_boy

Untitled

Apr 24th, 2022 (edited)
443
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. $destination = "YourDestination"
  2. $name = "MovedDoubles_temp"
  3. if(Test-path $destination\$name){Write-host "Temp folder already created"}
  4. else
  5. {New-Item "$destination\$name" -ItemType Directory}
  6.  
  7. $allfileshash = gci $destination -recurse | Get-FileHash | Group-Object -Property hash
  8.  
  9. $doubles = $allfileshash | where {$_.Count -gt 1}
  10.  
  11. foreach($double in $doubles)
  12. {          
  13.     $FilesToMove = $double.group.path
  14.    
  15.     foreach($FileToMove in $FilesToMove)
  16.     {Move-Item -Path $filetomove -Destination "$destination\$name"}
  17.    
  18.     $FilesInTemp = GCI "$destination\$name"
  19.     $filecount = $FilesInTemp.count -1
  20.     $filesintemp | sort CreationTime -Descending | select -Last $filecount | remove-item
  21.  
  22.     GCI "$destination\$name" | Move-Item -Destination $destination        
  23. }
  24. Remove-Item $destination\$name
Advertisement
Add Comment
Please, Sign In to add comment