Create new dir into every user's shared folder

Hey Experts.  Every user has a folder on our file server that they can save documents.  I need to copy a new directory (X) to their user folder (\User.A).  How can I accomplish this (preferably with Powershell)?

On the file server:

Thanks Experts!
Who is Participating?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

NVITEnd-user supportCommented:
Here's a .cmd version:
@echo off
setlocal enabledelayedexpansion

set newdir=newdirX
set srcdir=E:\source\src\%newdir%
set tgtdir=E:\Shared\Users

for /d %%k in ("%tgtdir%\*") do (
   md "%%~fk\%newdir%"
   xcopy /y /e "%srcdir%" "%%~fk\%newdir%\"

Open in new window

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
Jose Gabriel Ortega CastroCEO Faru Bonon IT - EE Solution ExpertCommented:
Can you add the Source and the Target? (no matter if it's changed for the real), just to have us an idea.
Do you want to copy the folder into everybody's shared?
rastoiWindows DTS expertCommented:
Just like Jose mentioned, it is unclear, what you want to achieve. To copy some existing folder into each directory in E:\shared\users is this the way. Just careful with '-Force' it will overwrite the content if such folder already exist in destination.

Get-ChildItem -Directory -path E:\Shared\Users |% {Copy-Item -path d:\data\X -Destination $_ -Recurse -Force} 

Open in new window

Big Business Goals? Which KPIs Will Help You

The most successful MSPs rely on metrics – known as key performance indicators (KPIs) – for making informed decisions that help their businesses thrive, rather than just survive. This eBook provides an overview of the most important KPIs used by top MSPs.

Sajen JoseCommented:
You can use the below script:

$NewFolderToCopy = "C:\Temp\myNewFolder"
$UserFolders = Get-ChildItem -Path "C:\Temp\Users\"

ForEach ($user in $UserFolders)
    Copy-Item -Path $NewFolderToCopy -Destination $user.FullName -Recurse
rastoiWindows DTS expertCommented:
Sajen, your script is the same like my oneliner above, I see small issue in your code. If there are files within .\Users, they will become entriers in your $UserFolders and $user respectively. I recommend to Add '-Directory' into Get-childitem parameters to fix this.
samiam41Author Commented:
Thank you experts for the scripts!

NVIT, I ended up using your script as it was first and I started my project once I had it.

I will test the others when I get a chance.  If I run out of time, I will have to close it out with NVIT being awarded the best solution.

Regardless, thanks for the suggestions.  Updates forthcoming.
NVITEnd-user supportCommented:
The author used solution given by NVIT
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today

From novice to tech pro — start learning today.