I found a code here (on this site) which allows copying of files changed in last 20 days. My issue is that I have a folder with many subfolders and some subfolders could be 8 or more levels deeps. I need to copy files changed to destination folder and maintain the folder structure. How could this be changed to allow recursively copy files and maintain same folder structure. Below is code:
$DestinationFolder = "c:\temp1\"
$EarliestModifiedTime = (Get-date).AddDays(-20)
$Files = Get-ChildItem "c:\temp\*.*"
foreach ($File in $Files) {
if ($File.LastWriteTime -gt $EarliestModifiedTime)
{
Copy-Item $File -Destination $DestinationFolder
Write-Host "Copying $File"
}
else
{
Write-Host "Not copying $File"
}
}