Get-Child and Copy-Item

So I wrote the following code to get txt files, pipe it, and then copy them to a destination.

Get-ChildItem -Path "C:\Source" -Recurse |
Where {$_.FullName -Like '*.txt*'} |
Copy-Item $_.FullName -Destination "C:\Destination"

The problem is that the script would not work this way, so I kept looking around and found an example of a script similar to mine but they use % and {} brackets at the copy-item command. I’m trying to understand what the difference means.

Get-ChildItem -Path "C:\Source" -Recurse |
Where {$_.FullName -Like '*.txt*'} |
% {Copy-Item $_.FullName -Destination "C:\Destination"}

If you are just searching for text (.txt) files, you should filter with Get-ChildItem:

Get-ChildItem -Path C:\Test\* -Recurse -Include *.txt -File | Copy-Item -Destination C:\Temp -WhatIf

Copy-Item accepts pipeline input, so there is no need to do a foreach loop either.

Yea that works. Thanks! One question though, I’m going to copy some really big files, does anyone know if PowerShell have a Multi-Threading feature just like Robocopy does?