locked
powershell script to copy list of items to list of locations? RRS feed

  • Question

  • I've got a long list of files I need to copy to a new location (more than 4,000 of them). The files are from various locations around a large file server. I have the list of the files, with full path, in a text file (origin.txt) where each file is on a separate line. The structure is something like this:

    \\originserver\firstfolder\subfolder\file1.extension
    \\originserver\secondfolder\file2.extension
    etc.

    I want to preserve the folder structure of the files though not copy everything else in those folders. As a result, I took the list of files with their complete path, removed the file names, and changed the path. I have the list of locations in a second text file (destination.txt) where each location is on a separate line. The structure is something like this:

    \\destinationserver\firstfolder\subfolder\
    \\destinationserver\secondfolder\
    etc.

    I want to copy the item from the first line of origin.txt to the first line of destination.txt and then the second to the second and so on. What's the best way to achieve this end? Should this be accomplished using copy-item or is there a better way? Anyone have a simple script that I could use to accomplish this? Thanks!

    Sunday, February 25, 2018 3:26 PM

All replies

  • Robo copy tends to work better and faster than PS in this case: https://docs.microsoft.com/en-us/windows-server/administration/windows-commands/robocopy 


    NOTICE: Posts are provided “AS IS” without warranty of any kind, either expressed or implied, including but not limited to the implied warranties of merchantability and/or fitness for a particular purpose.

    Sunday, February 25, 2018 4:03 PM
  • Thanks for the response. I was looking at robocopy when I first started thinking about this but I wasn't sure it would work for this. How would I use robocopy to step through the two lists? Ultimately what I really need is to only copy the 4,000+ files from the list to the new location while maintaining their folder structure as well (in part because the file names are similar or the same, one to the next, but in part because the folder will describe the content of the file contained therein. Any help would be greatly appreciate! Thanks!
    Sunday, February 25, 2018 4:42 PM
  • RoboCopy does not work well for "scatter-gather".  Copy the files in a loop and create the folder path first.

    Look in the Gallery for numerous examples.

    Even if you use RoboCopy it will have to be run in a loop.  Post in the Windows General forum for help with RoboCopy.  It is not part of PowerShell.


    \_(ツ)_/

    • Proposed as answer by BOfH-666 Sunday, February 25, 2018 9:00 PM
    Sunday, February 25, 2018 5:56 PM