Robocopy or Batch file to copy entire FOLDER to every profile's %localappdata% please

1.1k Views Asked by At

So I'm very new at batch files but have used command line for many purposes though not on the scale that I currently need....

My issue is that I've installed an application on one of our servers (actually 5 servers ..1 main and 4 additional but nearly identical servers) and I've discovered this application writes a folder into the \appdata\local\ directory that it will give an error upon running if ran by one of the client users on the server because they do not have write privileges to the C:\ drive.

So......I'v tested and confirmed that application runs fine if I just copy over the folder into the %LOCALAPPDATA% of the profile i'm testing...thing is...there is a LOT of profiles on just 1 of the servers and I don't want to have to copy this folder manually to all profiles on all 5 servers...will take me all night...

Can someone please help me with a 100% working code for doing this in a batch file? I've read post after post and no one else seems to have this exact issue OR they are wanting specific files copied and not the entire folder/subfolder as I need and I'm extremely reticent to go modifying one of the other answers because I don't know enough to be sure I don't make a time consuming mistake...

Thank you in advance for any help you can provide!

1

There are 1 best solutions below

6
On

I know you are looking for a batch file, but I think you can solve this very quickly with powershell.

$source = "C:\temp"
$servers = "Server1","Server2","Server3"

foreach($node in $servers)
{
    $TargetFolders = Resolve-Path "\\$node\C$\Users\*\AppData\Local"

    foreach($destination in $TargetFolders)
    {
        Robocopy "$source" "$destination" /e /r:0 /w:0
    }
}

Test this out before you run it on a production system. I typed it up without testing it myself.