Copy network folder to all users under C:users\*\appdata

I'm trying to copy a network folder to C:\users\*AppData\Local\Autodesk\C3d 2023\Enu\. I need the folder to be copied to all existing users profiles. If the folder does not exist it should also be created.

I have this powershell script but I get invalid characters error for the wild card. The script works if I specify a profile but that does not work for me since I want it for all the profiles.

$Source = '\\server\Templates\ ' 
$Destination = 'C:\users\*\AppData\Local\Autodesk\C3D 2023\enu\' 
if (!(Test-Path -path $Destination)) { New-Item $Destination -type Directory } 
Get-ChildItem $Destination | ForEach-Object { Copy-Item -Path $Source -Destination $_ -Recurse }
0

Comments

5 comments
Date Votes
  • I would use Get-ChildItem and then run a for loop. You could also add a blacklist if you don't want to run this against folders like the public user.

    $Source = '\\server\Templates\'
    $Destination = "\AppData\Local\Autodesk\C3D 2021\enu"
    $Test = $Null
    $Users = Get-ChildItem "C:\users\"
    $BlackList = "Administrator", "public"

    Foreach($User in $Users)
    {
        if($BlackList -notcontains $User)
                {
            $Test = Test-path "$($user.fullname)\$Destination"
            If ($False -eq $Test)
            {
                New-Item -Path "$($user.fullname)\$Destination" -Type Directory
            }
            Copy-Item -Path $Source -Destination "$($user.fullname)\$Destination"
            $Test = $Null
        }
    }

    0
  • Thank you sir you are my hero! I spent days trying to get this to work and even reached out to vendors who couldn't get me a proper script.

    I also just had to add -Recurse after \$Destination" in the copy item line, otherwise the contents of the folder were not getting copied.

    0
  • One more question, what can I add if the folder already exists and I wish to over-write whatever is in there?

    0
  • Thank you again, that was it.

    0

Please sign in to leave a comment.

Didn't find what you were looking for?

New post