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?
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.

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
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

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
Has Powershell sent you back into the Stone Age?

If managing Active Directory using Windows Powershell® is making you feel like you stepped back in time, you are not alone.  For nearly 20 years, AD admins around the world have used one tool for day-to-day AD management: Hyena. Discover why.

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.
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.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.