Solved

Copy one file to multiple subfolders by Powershell

Posted on 2013-06-13
4
1,206 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
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 68

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

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

A procedure for exporting installed hotfix details of remote computers using powershell
A brief introduction to what I consider to be the best editor for PowerShell.
In this Micro Tutorial viewers will learn how to restore their server from Bare Metal Backup image created with Windows Server Backup feature. As an example Windows 2012R2 is used.
This tutorial will walk an individual through the process of installing of Data Protection Manager on a server running Windows Server 2012 R2, including the prerequisites. Microsoft .Net 3.5 is required. To install this feature, go to Server Manager…

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

22 Experts available now in Live!

Get 1:1 Help Now