Script copy multiple files to different locations + log file

Hi there,

I spent some time learning PS, but couldn’t find anything which to solve my idea. I would like to copy different files with different names and every file should go to different location. For example
source: folder X & file1 - destination: folder Y1
source: folder X & file1_2 - destination: folder Y4
source: folder X2 & file2 - destination: folder Y2
source: folder X3 & file3 - destination: folder Y3

As you see there are a different sources and different destinations.
I have to use filter as well to exclude file1_2 from copying it to folder Y1.
How to achive that ?

Get-ChildItem C:\testX -Filter file_1 | Copy-Item -Exclude file1_2 -Destination D:\testY1
Get-ChildItem C:\testX -Filter file_1_2 | Copy-Item -Destination D:\testY4
Get-ChildItem C:\testX2 -Filter file_2 | Copy-Item -Destination D:\testY2
Get-ChildItem C:\testX3 -Filter file_3 | Copy-Item -Destination D:\testY3

Would be great if log files can catch all of the copying.

Welcome to the forum. :wave:t4:

Sorry for the late answer.

The informations you give are a little vague. How are the files and the destination folders related?

If you know the exact file name you don’t need a Get-ChildItem. You can specify the file you want to copy directly for Copy-Item.

Before we dive too deep into that topic … is that really necessary? In my experiences it is more important to know if something went wrong … and to catch errors you could use a proper error handling with a try catch block.