The below function flattens the directory structure and copies files based on the last write date chosen.
function mega-copy($srcdir,$destdir,$startdate,$enddate)
{
$files = Get-ChildItem $SrcDir -recurse | Where-Object { $_.LastWriteTime -ge "$startdate" -and $_.LastWriteTime -le "$enddate" -and $_.PSIsContainer -eq $false };
$files|foreach($_)
{
cp $_.Fullname ($destdir+$_.name) -Verbose
}
}
This has been very successful on smaller directories, but when attempting to use it for directories with multiple sub-directories and file counts ranging from the hundreds of thousands to the tens of millions, it simply stalls. I ran this and allowed it to sit for 24 hours, and not a single file was copied, nor did anything show up in the PowerShell console window. In this particular instance, there were roughly 27 million files.
However a simplistic batch file did the job with no issue whatsoever, though it was very slow.