Super User is a question and answer site for computer enthusiasts and power users. It's 100% free, no registration required.

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I wrote this code to copy files, what I need is a way to make it copy just the files created this month or created last 31 days?

$a = "L:\EndMonths\"
$a +=get-date -format MMMM
xcopy "L:\28*.zip" $a /I
xcopy "L:\29*.zip" $a /I
xcopy "L:\30*.zip" $a /I
xcopy "L:\31*.zip" $a /I
share|improve this question
up vote 2 down vote accepted

To get files from this month, use:

$date = Get-Date -Format M-1-y

or to get files from the last 31 days use:

$date = (Get-Date).AddDays(-31).ToString('M-d-y')

Then call xcopy like:

xcopy "L:\28*.zip" $a /I /D:$date
share|improve this answer
This what I need, Thanks – Mahmoud AL-saadi Jan 31 '12 at 20:10

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.