Solved

copying folders in powershell

Posted on 2011-03-09
8
835 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
[X]
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
  • 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
Free NetCrunch network monitor licenses!

Only on Experts-Exchange: Sign-up for a free-trial and we'll send you your permanent license!

Here is what you get: 30 Nodes | Unlimited Sensors | No Time Restrictions | Absolutely FREE!

Act now. This offer ends July 14, 2017.

 
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

Stressed Out?

Watch some penguins on the livecam!

Question has a verified solution.

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

Always backup Domain, SYSVOL etc.using processes according to Microsoft Best Practices. This is meant as a disaster recovery process for small environments that did not implement backup processes and did not run a secondary domain controller that ne…
The Windows functions GetTickCount and timeGetTime retrieve the number of milliseconds since the system was started. However, the value is stored in a DWORD, which means that it wraps around to zero every 49.7 days. This article shows how to solve t…
The viewer will learn how to look for a specific file type in a local or remote server directory using PHP.
Attackers love to prey on accounts that have privileges. Reducing privileged accounts and protecting privileged accounts therefore is paramount. Users, groups, and service accounts need to be protected to help protect the entire Active Directory …

729 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