Copy-Item (based on the creationtime property)

Hello Forum,
I am very new to powershell, I started learning yesterday.
I have been playing around with the “Copy-Item” cmdlet, and like what I can do with it.

I wondered if there was a way of copying files, based on their Property “CreationTime” as I can already do with copying spefic file types?

I have been playing with both the -Filter and -Exclude paramaters but with no luck so far.

So example.

copy from C:\testfolder1\ to C:\testfolder2
but only copy files from 2014.

I would be greatful for any help you can offer.

Kind Regards
Stephen Murphy

-Filter and -Exclude operate against the filename. You’ll need an interim filter.

Get-ChildItem c:\source |
Where-Object CreationTime -gt [datetime]'1/1/2001' |
Copy-Item c:\destination

Something vaguely like that, conceptually.

Don, thats lovely thank you, I think I understand a bit better now.
Can you do the same with -gt “12 months” or “30 days” or does it have to be specific dates?

No, you have to have an actual value. It’s just like comparing two numbers. But you can make one.

$tomorrow = (Get-Date).AddDays(1)

Pretty sure it’s all in “Learn PowerShell in a Month of Lunches” if you want to explore deeper :).