Powershell or Batch File Copy w/Loop

grahamco
grahamco used Ask the Experts™
on
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
Comment
Watch Question

Do more with

Expert Office
EXPERT OFFICE® is a registered trademark of EXPERTS EXCHANGE®
Co-Founder and Chief Architect
Top Expert 2016
Commented:
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

Author

Commented:
Thanks Dustin that worked perfectly!..

Do more with

Expert Office
Submit tech questions to Ask the Experts™ at any time to receive solutions, advice, and new ideas from leading industry professionals.

Start 7-Day Free Trial