• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 853
  • Last Modified:

copying folders in powershell

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
gd6627
Asked:
gd6627
  • 4
  • 4
1 Solution
 
t-maxCommented:
0
 
gd6627Author Commented:
not what i was looking for but itsa start i need to copy to multiple folders
0
 
t-maxCommented:
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
Simplify Active Directory Administration

Administration of Active Directory does not have to be hard.  Too often what should be a simple task is made more difficult than it needs to be.The solution?  Hyena from SystemTools Software.  With ease-of-use as well as powerful importing and bulk updating capabilities.

 
t-maxCommented:
Correction:
Write-host  "Copying files from $source to $target";
Hope the rest is fine.
0
 
gd6627Author Commented:
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
 
gd6627Author Commented:
correction: Target list the names of folders i want to copy to?
0
 
t-maxCommented:
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
 
gd6627Author Commented:
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
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

Join & Write a Comment

Featured Post

Get 10% Off Your First Squarespace Website

Ready to showcase your work, publish content or promote your business online? With Squarespace’s award-winning templates and 24/7 customer service, getting started is simple. Head to Squarespace.com and use offer code ‘EXPERTS’ to get 10% off your first purchase.

  • 4
  • 4
Tackle projects and never again get stuck behind a technical roadblock.
Join Now