Solved

copying folders in powershell

Posted on 2011-03-09
8
826 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
Netscaler Common Configuration How To guides

If you use NetScaler you will want to see these guides. The NetScaler How To Guides show administrators how to get NetScaler up and configured by providing instructions for common scenarios and some not so common ones.

 

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

Netscaler Common Configuration How To guides

If you use NetScaler you will want to see these guides. The NetScaler How To Guides show administrators how to get NetScaler up and configured by providing instructions for common scenarios and some not so common ones.

Question has a verified solution.

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

Create and license users in Office 365 in bulk based on a CSV file. A step-by-step guide with PowerShell script examples.
This article explains how to prepare an HTML email signature template file containing dynamic placeholders for users' Azure AD data. Furthermore, it explains how to use this file to remotely set up a department-wide email signature policy in Office …
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 from a Windows Server 2008 domain controller to a Windows Server 2012 domain controlle…
This Micro Tutorial hows how you can integrate  Mac OSX to a Windows Active Directory Domain. Apple has made it easy to allow users to bind their macs to a windows domain with relative ease. The following video show how to bind OSX Mavericks to …

863 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

25 Experts available now in Live!

Get 1:1 Help Now