Powershell-Question Copy folder with permissions to multiple servers

Dan GH 1 Reputation point
2020-12-01T16:13:18.407+00:00

Good Morning

I am new to powershell and I am struggling with the following scenario.

I have a folder that is set with specific security/permissions settings on 1 server and i need to copy that 1 folder to multiple servers with the same security/permission settings.

I know Robocopy could easily do this from 1 server to another server, but I need to copy it to multiple servers at once.

So I found the following site with information on creating a folder on multiple servers
https://powershell.org/forums/topic/creating-a-folder-remotely-using-variables/
that was helpful in creating the folder but I am unsure how to copy the the security/permissions?

any guidance on an approach would be helpful

Thank you

Windows Server PowerShell
Windows Server PowerShell
Windows Server: A family of Microsoft server operating systems that support enterprise-level management, data storage, applications, and communications.PowerShell: A family of Microsoft task automation and configuration management frameworks consisting of a command-line shell and associated scripting language.
5,520 questions
0 comments No comments
{count} votes

5 answers

Sort by: Most helpful
  1. Andreas Baumgarten 108.7K Reputation points MVP
    2020-12-01T17:03:17.47+00:00

    Maybe this is helpful:

    Get-Acl \\server01\share\test1 | Set-Acl \\server02\share\test1
    

    (If the reply was helpful please don't forget to upvote and/or accept as answer, thank you)

    Regards
    Andreas Baumgarten

    2 people found this answer helpful.
    0 comments No comments

  2. MotoX80 33,481 Reputation points
    2020-12-01T17:16:08.977+00:00

    Some thoughts. No matter what tool you use to mirror the folders between the multiple servers, there is going to be a time lag while the folders are created and the file data copied. So it all depends on how long your applications can "live with" partially synchronized folders. I think that it is going to be hard for you to recreate the efficiency that already exists in robocopy with your own script.

    So the easiest thing to do would be to launch a robocopy process in parallel for each server using Powershell jobs.

    https://devblogs.microsoft.com/scripting/parallel-processing-with-jobs-in-powershell/

    Instead of, say, a bat file that robocopy's the files to server A, then server B, you would have multiple robocopy's that run at the same time. Now when they finish is going to be a function of network bandwidth and how much data you copy and how responsive the destination servers are.

    You could take that one step further and robocopy each folder/file/subfolder 1 at a time with jobs. It all depends on your application requirements.

    0 comments No comments

  3. Ian Xue 36,751 Reputation points Microsoft Vendor
    2020-12-02T09:32:05.02+00:00

    Hi,

    According to the link you give, I assume that you create folders with a foreach loop. If you don't need to copy folders to multiple servers simultaneously, you can just invoke robocooy in the loop.

    $servers | foreach{ robocopy $source $destination /E}  
    

    Best Regards,
    Ian

    ============================================

    If the Answer is helpful, please click "Accept Answer" and upvote it.
    Note: Please follow the steps in our documentation to enable e-mail notifications if you want to receive the related email notification for this thread.

    0 comments No comments

  4. Dan GH 1 Reputation point
    2020-12-04T22:20:31.68+00:00

    Thank you for the responses, I am curious about answer 3.

    $servers | foreach{ robocopy $source $destination /E}

    if you use the server variable with the list of servers to copy the 1 folder with its permissions how would you identify the variable in the {expression}

    $SRV=srv1,srv2,srv3
    $SRV | foreach { robocopy d:\folder1 ??\d$ \copyall }

    it is just a folder with 4 small files in it that is being copied to multiple systems but it is the permission settings on that folder that need to be copied.

    0 comments No comments

  5. MotoX80 33,481 Reputation points
    2020-12-04T23:52:22.893+00:00

    What permissions are you applying? You should be using Active Directory groups and adding/removing users from/to the groups. Set the correct access on the folders, then you don't need to replicate the permissions on the files.

    $Servers = @('srv1','srv2','srv3')
    foreach ($Srv in $Servers) {
        "Processing $Srv"
         robocopy d:\folder1 \\$Srv\d$\folder1  /sec /e  /l 
    } 
    
    0 comments No comments

Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.