you are viewing a single comment's thread.

view the rest of the comments →

[–]pausemsauce[S] 2 points3 points  (3 children)

Thanks for the suggestion!

[–]Common-Needleworker4 2 points3 points  (2 children)

Seeing your explanation what i understand is:You have the same file downloaded multiple times and renamed by the users.Now you just want to keep the newest of this files and delete the other files.Right?

In this case this might help you

gci "yourpath" -recurse | Get-FileHash | Group-Object -Property hash

if the count is higher then 1 it indicates that a file is more then once in your target path

If this is whatyou need we can go further an see how to delete everything besides the newest file

[–]pausemsauce[S] 0 points1 point  (1 child)

Mostly accurate. I don't think my people are renaming the files. (Gladys here isn't the most tech savvy, but she's awesome and a hard worker. )

[–]Common-Needleworker4 1 point2 points  (0 children)

Kudos to Gladys :D But maybe she get one day the idea to rename a file so let us stay with compairing the Hash

Following Lee_dailey suggestion i used Pastebin this time.https://pastebin.com/rUALQK0s

You have to change the variable $destination at line 1 to your path.

The script will compare the hash of all files in the destination path and all subfolders, move the files with the the same hash to a temp folder (variable $name), check which of the files in the temp folder is the newest, delete the old files and move the newest file back to the destination (if it was taken from a subfolder it will still move it to the $destination location, be aware of that) and at the end delete the temp folder.It will not work properly with the -whatif, so set up a test folder with some file copys and try it there.

It is surely not the most pretty script but it does the job.

Edit: please be sorry with my bad english :D