Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people, just like you, are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
Solved

copying folders in powershell

Posted on 2011-03-09
8
831 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
Resolve Critical IT Incidents Fast

If your data, services or processes become compromised, your organization can suffer damage in just minutes and how fast you communicate during a major IT incident is everything. Learn how to immediately identify incidents & best practices to resolve them quickly and effectively.

 
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

Featured Post

VMware Disaster Recovery and Data Protection

In this expert guide, you’ll learn about the components of a Modern Data Center. You will use cases for the value-added capabilities of Veeam®, including combining backup and replication for VMware disaster recovery and using replication for data center migration.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Restoring deleted objects in Active Directory has been a standard feature in Active Directory for many years, yet some admins may not know what is available.
This article runs through the process of deploying a single EXE application selectively to a group of user.
The viewer will learn how to dynamically set the form action using jQuery.
In this seventh video of the Xpdf series, we discuss and demonstrate the PDFfonts utility, which lists all the fonts used in a PDF file. It does this via a command line interface, making it suitable for use in programs, scripts, batch files — any pl…

856 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