Go Premium for a chance to win a PS4. Enter to Win

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 1477
  • Last Modified:

Copy one file to multiple subfolders by Powershell

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
CyruzQ
Asked:
CyruzQ
2 Solutions
 
Meir RivkinFull stack Software EngineerCommented:
Get-ChildItem -Path \\server2\profiles | ?{ $_.PSIsContainer } | Copy-Item '\\server1\profiles\username.domain.V2\appsFolder.itemdata-ms' -Destination $_.fullname

Open in new window

0
 
QlemoC++ DeveloperCommented:
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

Keep up with what's happening at Experts Exchange!

Sign up to receive Decoded, a new monthly digest with product updates, feature release info, continuing education opportunities, and more.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now