Reputation: 243
I'm trying to copy files (.zip) that has been created in the last half an hour and using the below script for that but for some reason all the zip files in the source directory get copied over. Can you please help me in correcting it?
copy-item C:\ABC\\*.zip -filter (Get-ChildItem | Where{$_.CreationTime -ge (Get-Date).AddMinutes(-30)}) -destination C:\
Upvotes: 1
Views: 2421
Reputation: 5558
Try the following:
Get-ChildItem C:\ABC\*.zip | Where { $_.CreationTime -ge (Get-Date).AddMinutes(-30) } | % { Copy-Item $_.FullName -destination C:\ }
I am not sure why filter
is not working, but this gets a list of all the zips, filters that down to the ones with the correct times, and then issues the copy statement.
Upvotes: 3