Solved

Copy one file to multiple subfolders by Powershell

Posted on 2013-06-13
4
1,293 Views
Last Modified: 2014-09-30
Hello

I am new to powershell and has gone a bit cold for something that I thought was simple.

We use Microsoft Server 2012 RDS for terminal clients. where we use a "dummy user" to create a default Metro tiles start menu.

When we make changes in the start menu, I want the appsFolder.itemdata-ms  file Copied to all user profiles at night when they are offline.

so i need a powershell script there can copy one file from a folder to all subfolders in another folder.
is there a way to do this without the need to list all the subfolders by name. They change all the time

something like "copy \\server1 \ profiles \ username.domain.V2 \ appsFolder.itemdata-ms to \\server2 \ profiles \" all folders "?
0
Comment
Question by:CyruzQ
[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 Comments
 
LVL 42

Accepted Solution

by:
sedgwick earned 250 total points
ID: 39243774
Get-ChildItem -Path \\server2\profiles | ?{ $_.PSIsContainer } | Copy-Item '\\server1\profiles\username.domain.V2\appsFolder.itemdata-ms' -Destination $_.fullname

Open in new window

0
 
LVL 70

Assisted Solution

by:Qlemo
Qlemo earned 250 total points
ID: 39297470
That works, but only with PS 3. If you want to execute it with PS 2:
Get-ChildItem \\server2\profiles | ? { $_.PsIsContainer } | select @{l='Destination'; e={$_.FullName}} | copy-item -Path '\\server1\profiles\username.domain.V2\appsFolder.itemdata-ms'

Open in new window

0

Featured Post

Free Tool: Site Down Detector

Helpful to verify reports of your own downtime, or to double check a downed website you are trying to access.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

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.
Recently we ran in to an issue while running some SQL jobs where we were trying to process the cubes.  We got an error saying failure stating 'NT SERVICE\SQLSERVERAGENT does not have access to Analysis Services. So this is a way to automate that wit…
In this Micro Tutorial viewers will learn how they can get their files copied out from their unbootable system without need to use recovery services. As an example non-bootable Windows 2012R2 installation is used which has boot problems.
Exchange organizations may use the Journaling Agent of the Transport Service to archive messages going through Exchange. However, if the Transport Service is integrated with some email content management application (such as an antispam), the admini…

739 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