2
votes

I need to copy files modified within a certain time range to a destination directory along with the folder structure. I am using the below powershell script

PS C:\2015-06-27\tfs> get-childitem -recurse | where-object {$_.lastwritetime -gt '06-27-15 01:00' -AND $_.lastwritetime -LT
'06-27-15 11:59' -AND ! $_.PSIsContainer} | Copy-Item -destination c:\test -container - recurse

This copies the files but does not retain the source directory structure. How can I get the files copied and created in their respective directories ?

1

1 Answers

0
votes

Looks like your issue is with:

-AND ! $_.PSIsContainer} 

Since you're not targeting containers you won't be able to keep the folder structure as desired.

get-childitem -recurse | where-object {$_.lastwritetime -gt '06-27-15 01:00' -AND $_.lastwritetime -LT '06-27-15 11:59'} | Copy-Item -destination c:\test -recurse

Works fine for me.