How can I copy all files of kind:docx from all directories under and including e.g. D:\Doc_Source, to destination E:\Doc_Destination, in batches of e.g. 500, and only when there are none left in E:\Doc_Destination, except if they have string 'somestring' in the filename..?

I really appreciate any help I'm gonna get on this - I'm very new to PowerShell and thank you in advance.


except if they have string 'somestring' in the filename..?

I assume you want to exclude based on file name, if so change $exclude="text" to equal what you want to exclude.


$files = Get-ChildItem -recurse $source -Filter $ext | Where-Object {$_.Name -NotMatch $exclude}

ForEach ($file in $files) {
    Copy-Item -Path $file.Fullname -Destination $dest -Force 
| improve this answer | |
  • Just realized I missed the batches portion, this will copy all files at once. I'll get back to you on that. – CML Mar 9 '16 at 15:51
  • Are you looking to copy 500 then pause ? – CML Mar 9 '16 at 16:28
  • I guess CHECK if DESTINATION has ZERO, then COPY 500 and PAUSE, and CHECK if DEST..... – vixbix Mar 9 '16 at 16:52
  • Anyone else able to add to the work CML started? – vixbix Mar 10 '16 at 11:16

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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