I'm using the below powershell script to move files from $Source to $Destination based on a date range. During testing, it's moving all of files within a directory that may have been updated within the date range, but I only require the updated or new files with the Directory/Subdirectory. I like how it's working, except for copying everything.
Any thoughts on how the script can can be tweaked?
$source = "C:\Documents and Settings"
$destination = "C:\Documents and Settings\Test"
[datetime]$start = '2/18/2021 11:00:00'
[datetime]$end = '2/18/2021 11:15:00'
#Prod
dir $source | %{ dir $_.FullName | ?{ $_.LastWriteTime -gt $start-and $_.LastWriteTime -lt $end } |
Copy-Item -Destination $destination -Recurse -Force }