Solved

copying folders in powershell

Posted on 2011-03-09
8
825 Views
Last Modified: 2012-08-13
How can i copy a folder from one location into many folders using powershell for exanple i have a folder called wnos c:\wnos
and i have several files and folders inside the wnos folder.  i like to copy the contents of this folder to several folders using powershell      
0
Comment
Question by:gd6627
  • 4
  • 4
8 Comments
 
LVL 6

Expert Comment

by:t-max
ID: 35087378
0
 

Author Comment

by:gd6627
ID: 35087941
not what i was looking for but itsa start i need to copy to multiple folders
0
 
LVL 6

Expert Comment

by:t-max
ID: 35088455
Well, maybe something like this is closer to your needs:
$source=c:\source
$targetlist=c:\t1,d:\target2,d:\target2\t3

foreach ($target in $targetlist)
{
Write-host  "Copying files from " $source " to " $target;
Copy-Item $source\* $target;
}

Open in new window

Disclaimer: some little debugging might be necessary (I'm on a Mac now).
0
 
LVL 6

Expert Comment

by:t-max
ID: 35088572
Correction:
Write-host  "Copying files from $source to $target";
Hope the rest is fine.
0
 

Author Comment

by:gd6627
ID: 35088938
Ok is target list the names of the folders i want to ? If so say i have 100 folders is there a shorter way of doing it?
0
 

Author Comment

by:gd6627
ID: 35088942
correction: Target list the names of folders i want to copy to?
0
 
LVL 6

Accepted Solution

by:
t-max earned 500 total points
ID: 35089035
Yes, $targetlist holds the list of directories where you want to copy the files in $source.
Right now, where do you have this list of 100 folders?
If they are all inside a common parent folder (ie: c:\parent hols c:\parent\target1 to c:\parent\target100) then we can get the list of target folders fairly easy with get-childitem.
It's also possible if it's inside a text file.
0
 

Author Comment

by:gd6627
ID: 35162309
ok so if i have a list of folders in c: (or a text file with folder names) and i want to copy them to say \\server\folder then your script should work ..fairly simple right?
0

Join & Write a Comment

Disabling the Directory Sync Service Account in Office 365 will stop directory synchronization from working.
Create and license users in Office 365 in bulk based on a CSV file. A step-by-step guide with PowerShell script examples.
The viewer will learn how to dynamically set the form action using jQuery.
The viewer will learn how to create and use a small PHP class to apply a watermark to an image. This video shows the viewer the setup for the PHP watermark as well as important coding language. Continue to Part 2 to learn the core code used in creat…

762 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

18 Experts available now in Live!

Get 1:1 Help Now