I(absolute beginner in powershell) have been trying to create powershell script powershell script to copy files and folders created a day before to another drive. The source is a some what complicated structure which has several folders and files under one main folder. The files and folders get created every day. Objective is to copy all the files and folders created a day before under the main folder to the mainbackup folder. I would like to run this script everyday to keep the main and the mainbackup folder in sync. So far I have come until here:
This script works but it takes for ever and goes through every file and folder in the source and throws “already exists” message. Is there a way to only to look only for files created a day before or 24 hours before, and copy them to destination? Any advice is appreciated.
I have not tested this too much but I believe you want to use ‘-le’ instead of ‘-f’. I have never seen/used ‘-f’ before but you may just know something I do not.
Thanks for the input. I started the script with robocopy but gave up and moved on to copy-item. Haven’t used the /a and going to give it a try. It seems that robocopy just doesn’t handle so many files and folders. It appears that it just copies the newly created folders and not the files in those folders.
Thanks for the input. I have tried the -le and -ge. But they seem to do the same thing. The script still goes through all the folders and not just the one created in the past 24 hours and gives “already exists” message.