Powershell Script to copy files based on date modifed to check newest file from a remote location

Question:

I am new to powershell scripting and i cant figure out why my script copies
all files and doesn’t seem to check the date and then copies all the files
anyway. I was trying to do by days and minutes too, but I am not quite sure
on how to do that. any help would be great!

Answer:

If you want to use Hours and minutes, instead of AddDays, just use the .AddMinutes(), .AddHours(), or .AddSeconds() methods instead.

For what it’s worth, I made a small modifcation, adding an Else{Scriptblock} to the script to echo out the files which aren’t being copied. As written your code will only copy files written in the last 24 hours.

Source:

Powershell Script to copy files based on date modifed to check newest file from a remote location by licensed under CC BY-SA | With most appropriate answer!

Leave a Reply