invoke Emcopy (or Robocopy) in PS

I need to copy multiple folders to a new location. only select folders need to be copied in the source directory which can be supplied via a file, but I am having trouble figuring out how to use emcopy or robocopy within PS to do this. I have tried many combinations and have not found something which will work. Since I have several hundred folders to move, it would be nice to do this via script.

get-content c:\tmp\file.txt | invoke-command “./emcopy” (dest directory) (switches)

I was thinking something like this, but cannot find the correct combination. I am a low to average PS scripter, so please take it easy on me…Any help is much appreciated.

I have also tried to use 'copy-item, which does work well, but it is way too slow.

$source = Get-Content \\path\to\sourcefile.txt
$dest = '\\path\to\destinationfolder'
foreach ($folder in $source){
    $leaf = Split-Path $folder -Leaf
    $newdest = join-path $dest -ChildPath $leaf
    Robocopy.exe $folder $newdest /E /COPY:DATSO

Thank you for the input. How can I copy the folder names also? The code will copy all of the files and sub-folders into the root of the destination, but I need to preserve the folder names also

Example Source has

Destination needs the same.

Can you provide sample contents of your input text file and your desired results? The full paths would be helpful

The source would be like this:

these folders will be in a txt file, as I don’t need all of them, just lets say folder1 and folder 3.

I will be moving them to the destination \server2\share2\folder1, \server2\share2\folder3, etc

The code above is helpful, but it takes the contents of folder1 and folder3 and puts them at the root of \server2\share2 if I define $dest as \server2\share2.

I have several hundred of these to do and it is not practical to define each destination separately. Is there a way to define the ‘folder1, folder3’ names so they are written at the destination?

I modified my comment. Try it again.

I think that does it. I was looking at split-path but didn’t get it to work. Thanks so much for the help!

Excellent, glad I could help.