WebDevGuy
WebDevGuy

Reputation: 353

Powershell - How copy list of files to destination

I have a textfile (myfile.txt) that contains the source/destination of files to copy. For example....

c:\work\test1.txt \\server.usa.svr.com\sites\mysite\ztest1.txt
c:\work\test2.txt \\server.usa.svr.com\sites\mysite\ztest2.txt
c:\work\test3.txt \\server.usa.svr.com\sites\mysite\ztest3.txt
c:\work\test4.txt \\server.usa.svr.com\sites\mysite\ztest4.txt
c:\work\test5.txt \\server.usa.svr.com\sites\mysite\ztest5.txt
c:\work\test6.txt \\server.usa.svr.com\sites\mysite\ztest6.txt

Using powershell how can I open the file and copy from source to destination, for each file. Also, giving a status if error or success?

Thanks!

Upvotes: 0

Views: 578

Answers (1)

Joey
Joey

Reputation: 354356

If you don't have spaces in file names (or they are properly quoted) you can try the following:

Import-Csv myfile.txt -Delimiter ' ' -Header Path,Destination | Copy-Item

You can pipe to Copy-Item -WhatIf first to see whether it's doing the right thing.

Upvotes: 1

Related Questions