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.