# Move files to different drive

• ### Question

• Windows 2003 file server

Here is the script: (moves files that have not been accessed for 30 days to the drive E:\backup)

get-childitem P:\download -rec| where -FilterScript {$_.LastAccessTime -le [System.DateTime]::Now.AddDays(-30)} |move-item -destination "E:\backup" issue: all files results end up in one single file backup even I specify E:\backup. Questions: is there a way to move these files according to their source folder structures in the destination path E:\backup ex: source Target P:\download\it\1.txt E:\backup\it\1.tct P:\download\it\2\po.txt E:\backup\it\2\po.txt ------------------- Thank you. Tuesday, June 11, 2013 7:10 PM ### Answers • If you actually read the RoboCopy documentation you will see that it can be some. /MAXLAD:n :: MAXimum Last Access Date - exclude files unused since n. /MINLAD:n :: MINimum Last Access Date - exclude files used since n. (If n < 1900 then n = n days, else n = YYYYMMDD date). The answers you seek are all in the documentation. YOu just need to read it more carefully. ¯\_(ツ)_/¯ • Marked as answer by Thursday, July 11, 2013 3:45 AM Friday, June 14, 2013 3:09 PM ### All replies • Yes - use RoboCopy as it will do this easily and correctly. ¯\_(ツ)_/¯ Wednesday, June 12, 2013 3:13 PM • Thanks for the suggestion. Moving files that have not been accessed more than 30 days to the backup folder will be scheduled to run daily base the robocopy switch minlad is the specified date such as 20130512 and I can not set as variable to the task. minage is the age based on access date or modified date? Thank you. Wednesday, June 12, 2013 4:44 PM • I recommend reading all of the documentation carefully: robocopy /? ¯\_(ツ)_/¯ Wednesday, June 12, 2013 5:10 PM • John, Seems to work well for me using move-item. I keep the trailing \ after the e:\backup\. I guess when you filter with where it drops all Directories, obviously a directory will fail your check... Maybe change the script to sort through the source directory and build out the parallel structure in the destination. Then move files one directory at a time into the matching directory. Does that make any sense? Hope that helps! Jason Wednesday, June 12, 2013 9:46 PM • You can do it using the shell by just replacing, p:\download, with, e:\backup on each file's path property. Hope that helps! Jason Wednesday, June 12, 2013 9:47 PM • It works perfectly with RoboCopy with no changes. Just select the options you want. RoboCopy can be scheduled to constantly update and is more efficient and less demanding on resources. That is why Microsoft now includes in in all OS packages. ¯\_(ツ)_/¯ Wednesday, June 12, 2013 10:03 PM • Here - this moves without changing the timestamps. (default is DA add T to force copying of timestamps) ROBOCOPY <source> <destination> /E /MOV /MINAGE:30 /DCOPY:DAT ¯\_(ツ)_/¯ • Proposed as answer by Thursday, June 13, 2013 2:41 AM Wednesday, June 12, 2013 10:20 PM • I love using powershell but if the functionality is already there and easy to use in Robocopy then that's probably the best way to go. Hope that helps! Jason Thursday, June 13, 2013 2:42 AM • I love using powershell but if the functionality is already there and easy to use in Robocopy then that's probably the best way to go. Hope that helps! Jason PowerShell is very good at almost everything but it still is not able to do everything well all of the time. RoboCopy has been designed and evolved to handle complex repetitive copy and move tasks. If necessary we can control how many threads it uses and how often it breaks in order to prevent network saturation. I hope that the next version of PowerShell (it has been announced) will move the functionality of RoboCopy into a CmdLet. This is not absolutely necessary but may have some advantages. ¯\_(ツ)_/¯ Thursday, June 13, 2013 3:32 AM • Hi jrv, I tried to test ROBOCOPY <source> <destination> /E /MOV /MINAGE:30 /DCOPY:DAT out: I got invalid parameter /dcopy:dat?? I used ROBOCOPY <source> <destination> /E /MOV /MINAGE:30 /COPY:DAT to test out and find out the last accessed date on the source or destination has been changed to today's date. Is this supposed to be? I saw several posts regarding this: http://social.technet.microsoft.com/Forums/en-US/winservergen/thread/8f6f6a94-8da4-4779-9d1d-a3bc69fa48a2/ http://social.technet.microsoft.com/Forums/en-US/ITCG/thread/b5cb685e-32f6-4eed-855d-e710ca4b203f/ I used /b backup mode and the last access date is changed. any idea or advice? Thank you. • Edited by Thursday, June 13, 2013 3:45 PM Thursday, June 13, 2013 3:41 PM • Hi, Please copy and paste the exact command you are using, and the exact error message. (Remember, we can't see your screen.) Bill Thursday, June 13, 2013 3:51 PM • Please see the image. Thursday, June 13, 2013 4:14 PM • Type robocopy /? and read the list of options. When I do that it on my Windows 7 machine, I see the following in the list: /DCOPY:T :: COPY Directory Timestamps. This means you can write /DCOPY:T, but not /DCOPY:DAT. Bill Thursday, June 13, 2013 4:33 PM • This is Windows 2003 server and it could be why. Now, I am more concerned whether robocopy changes source files' last access date/time. Can anyone confirm or share? Thank you. • Edited by Thursday, June 13, 2013 7:00 PM Thursday, June 13, 2013 6:59 PM • Hi, Robocopy is a standard Microsoft tool. This forum is really focused on scripting. The best advice I can give is to experiment with robocopy to get your desired results. For further help using robocopy, please post in a more appropriate forum. Bill Thursday, June 13, 2013 7:11 PM • Hi Bill, I was testing jrv's suggestion to use robocopy and from my tests, robocopy can not move files based on access date that have not accessed for 30 days. back to my original question: I still can not get directories to be moved with files: I tried the below one script:$YourPath = "D:\"
$YourDest = "E:\Backup1\" if(!(test-path$YourDest))
{
new-item -type directory -path $YourDest } Get-ChildItem -Path$YourPath | where {$_.LastWriteTime -lt ((Get-Date).AddDays(-30))} | move-item -Destination$YourDest -ea silentlycontinue

-------------------

the directories do not copied either and als0 it did not check other folders under D.

Can anyone help?

Thank you.

• Edited by Friday, June 14, 2013 3:12 PM
Friday, June 14, 2013 3:04 PM
• If you actually read the RoboCopy documentation you  will see that it can be some.

/MAXLAD:n :: MAXimum Last Access Date - exclude files unused since n.
/MINLAD:n :: MINimum Last Access Date - exclude files used since n.
(If n < 1900 then n = n days, else n = YYYYMMDD date).

The answers you seek are all in the documentation.  YOu just need to read it more carefully.

¯\_(ツ)_/¯

• Marked as answer by Thursday, July 11, 2013 3:45 AM
Friday, June 14, 2013 3:09 PM