1

I am using Windows 10 and Powershell. I am moving a large directory of files onto a new server. The files will be easily copied over however the permissions will not be copied over. I have been working on creating a series of scripts to save all of the permissions for each level of the directory, and then be able to give the files in the new location the same pemissions at every level. This is what I have come up with for saving the permissions to file. (T:\ is the directory that the files are being moved from)

Note: I was going to use get-acl and set-acl but apparently you cannot use set-acl without rewriting the owner of each file.

$output = @()
ForEach ($item in (Get-ChildItem -Path T:\ -Recurse -Directory)) {

    ForEach ($acl in ($item.GetAccessControl().Access)){

        $output += $acl | 
            Add-Member `
                -MemberType NoteProperty `
                -Name 'Folder' `
                -Value $item.FullName `
                -PassThru
    }
}
$output | Export-Csv -Path .\outfile.csv -NoTypeInformation

This works to save the necessary information to file. My problem is in reloading all of the permissions once the files are in a new location. From what I have been able to find out I need to use the File.SetAccessControl(String, FileSecurity) Method. However everything I am trying is not working as desired.

Any help here? Maybe I am going about my goal all wrong.

  • 1
    Why not just use `robocopy` and preserve the permissions? – Bill_Stewart Jan 09 '20 at 22:29
  • Unfortunately a different team is handling the transferring of the files to the new server so I don't have any input into how it is being done. I was just told to figure out a way to save the permissions and then restore them. I still am unable to find a way to use File.SetAccessControl(String, FileSecurity) to load multiple ACL's from a file – Jeff Williams Jan 13 '20 at 20:49
  • I would communicate to the other team to use `robocopy` so that permissions are not lost, and then there's no need for a separate step. (Work smarter, not harder, as it were.) – Bill_Stewart Jan 13 '20 at 21:53

0 Answers0