Solved

copying folders in powershell

Posted on 2011-03-09
8
827 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
Windows Server 2016: All you need to know

Learn about Hyper-V features that increase functionality and usability of Microsoft Windows Server 2016. Also, throughout this eBook, you’ll find some basic PowerShell examples that will help you leverage the scripts in your environments!

 
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

Does Powershell have you tied up in knots?

Managing Active Directory does not always have to be complicated.  If you are spending more time trying instead of doing, then it's time to look at something else. For nearly 20 years, AD admins around the world have used one tool for day-to-day AD management: Hyena. Discover why

Question has a verified solution.

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

This article will help you understand what HashTables are and how to use them in PowerShell.
A procedure for exporting installed hotfix details of remote computers using powershell
This tutorial will walk an individual through the process of transferring the five major, necessary Active Directory Roles, commonly referred to as the FSMO roles to another domain controller. Log onto the new domain controller with a user account t…
The viewer will learn how to create a basic form using some HTML5 and PHP for later processing. Set up your basic HTML file. Open your form tag and set the method and action attributes.: (CODE) Set up your first few inputs one for the name and …

770 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