Hi all, does anyone have a good robocopy script to move files older than a specific date using the /MINAGE switch and also the /MINLAD?<\/p>\n
I have to move a truck load of files older that 7 years or not accessed in the last 3 years.<\/p>\n
Can’t quite figure the best way to approach this.<\/p>","upvoteCount":8,"answerCount":24,"datePublished":"2014-06-25T03:49:24.000Z","author":{"@type":"Person","name":"andrew-k","url":"https://community.spiceworks.com/u/andrew-k"},"acceptedAnswer":{"@type":"Answer","text":"
Try it out and let me know. I’ve run a few successful tests. This is part PS part Robo, copying of attributes gets nutty in ps…<\/p>\n
Edit: Changed to variable for export-csv<\/p>\n
#where the backup is going to be saved do not add \\ to the end of it. this plus the rest of the file path\n$backupDriveLetter = \"c:\\Backup\"\n\n$todaysdate = (Get-Date).ToString('MM-dd-yyyy')\n\n#create list of files lastaccessed more than 7 years\nGet-ChildItem –Path \"c:\\Users\\carusor\\desktop\\*\" –Recurse | Where-Object {$_.LastAccessTime –le (Get-Date).AddYears(-7)} | Select-Object FullName, LastAccessTime | Export-Csv -noclobber -append \"$backupdriveletter\\backup_$todaysdate.csv\"\n\n#create list of files lastaccessed more than 3 years matching these file types\nGet-ChildItem -Path \"c:\\Users\\carusor\\desktop\\*\" -Recurse -Include *.gif, *.jpg, *.xls, *.docx, *.pdf | Where-Object {$_.LastAccessTime -le (Get-Date).AddYears(-3)} | Select-Object FullName, LastAccessTime | Export-Csv -noclobber -append \"$backupdriveletter\\backup_$todaysdate.csv\"\n\n#imports the list of files we will backup\n$filestocopy = Import-Csv $backupDriveLetter\\backup_$todaysdate.csv\n\n#regex to replace drive letter on source ex. c: to d:\n$replaceDriveLetter = \"[^:]*:\"\n\nforeach ($line in $filestocopy) {\n\t\n\t$source = $line.FullName\n\t\n\t#create our destination path using regex from above and our source directory\n\t$destination = [regex]::Replace($source,$replaceDriveLetter,\"$backupDriveLetter\")\n\t\n\t#do some copying\n\trobocopy \"$source\" \"$destination\" /E /B /A+:A /COPYALL /DCOPY:T /R:3 /W:5 \n\t\n}\n<\/code><\/pre>","upvoteCount":2,"datePublished":"2014-06-27T13:58:09.000Z","url":"https://community.spiceworks.com/t/robocopy/315793/21","author":{"@type":"Person","name":"raycaruso","url":"https://community.spiceworks.com/u/raycaruso"}},"suggestedAnswer":[{"@type":"Answer","text":"Hi all, does anyone have a good robocopy script to move files older than a specific date using the /MINAGE switch and also the /MINLAD?<\/p>\n
I have to move a truck load of files older that 7 years or not accessed in the last 3 years.<\/p>\n
Can’t quite figure the best way to approach this.<\/p>","upvoteCount":8,"datePublished":"2014-06-25T03:49:24.000Z","url":"https://community.spiceworks.com/t/robocopy/315793/1","author":{"@type":"Person","name":"andrew-k","url":"https://community.spiceworks.com/u/andrew-k"}},{"@type":"Answer","text":"
robocopy c:\\source d:\\old /minage:20070625 /e /move\nrobocopy c:\\source d:\\old /minlad:20110625 /e /move\n\n<\/code><\/pre>\nWill something like this work for you?<\/p>","upvoteCount":3,"datePublished":"2014-06-25T04:04:37.000Z","url":"https://community.spiceworks.com/t/robocopy/315793/2","author":{"@type":"Person","name":"krzysztofradomski","url":"https://community.spiceworks.com/u/krzysztofradomski"}},{"@type":"Answer","text":"
Kind of, Krizz. I wanted to try to make it happen in a single move. That’s where I’m stuck. How to have robocopy process on both minage and minlad at the same time.<\/p>","upvoteCount":0,"datePublished":"2014-06-25T04:10:22.000Z","url":"https://community.spiceworks.com/t/robocopy/315793/3","author":{"@type":"Person","name":"andrew-k","url":"https://community.spiceworks.com/u/andrew-k"}},{"@type":"Answer","text":"
I’m afraid that if you use both quantifiers in single command they will be treated in conjunction, not disjunction. That’s why you need to do it twice.<\/p>","upvoteCount":3,"datePublished":"2014-06-25T04:20:09.000Z","url":"https://community.spiceworks.com/t/robocopy/315793/4","author":{"@type":"Person","name":"krzysztofradomski","url":"https://community.spiceworks.com/u/krzysztofradomski"}},{"@type":"Answer","text":"
You can put the both lines in a batch file or a powershell file and then run just that one script and both robocopys will run. Or were you looking for something that will copy files that are older than 7 years AND have not been touched in 3 years.<\/p>","upvoteCount":1,"datePublished":"2014-06-25T11:22:35.000Z","url":"https://community.spiceworks.com/t/robocopy/315793/5","author":{"@type":"Person","name":"tonystahl","url":"https://community.spiceworks.com/u/tonystahl"}},{"@type":"Answer","text":"
That will only process files though… If this is project based operation (i.e. a bunch of files in a different project folders) then the question is has anything in this folder been changed in the past 3 yrs if not move it to the archive folder. Otherwise you will be moving most of the project files but not all of them and create more headache. I don’t have a good solution for that but maybe someone else does. (I know I could use a script with that kind of logic to it)<\/p>","upvoteCount":1,"datePublished":"2014-06-25T12:23:25.000Z","url":"https://community.spiceworks.com/t/robocopy/315793/6","author":{"@type":"Person","name":"txheed","url":"https://community.spiceworks.com/u/txheed"}},{"@type":"Answer","text":"