Powershell or Batch File Copy w/Loop

We need to place a .rdp shortcut in the desktop folder of all our user's roaming profile. Looking for a script to quickly accomplish this. The user's roaming profile directory names are in this format: "username.contoso.V6", within this directory is a "desktop" directory which is where we'd like to copy the shortcut.

source: c:\folder\rdpshortcut.rdp
destination: \\gsf1\rds\username.contoso.V6\desktop
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.

Dustin SaundersDirector of OperationsCommented:
Something like this would do the trick for you

$source = "C:\folder\rdpshortcut.rdp"

$destination = "\\gfs1\rds\"

$children = Get-ChildItem -Path $destination | ?{ $_.PSIsContainer -and $_.Name -like "*.contoso.V6" }

foreach ($child in $children)
    $destPath = $child.FullName + "\desktop"
    Copy-Item -Path $source -Destination $destPath

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
grahamcoAuthor Commented:
Thanks Dustin that worked perfectly!..
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.