Copying the ACL
1 |
Get-Acl sourceFile | Set-Acl targetFile |
Copy files with the ACL
1 |
robocopy source target /e /z /sec |
Add Permission on File
1 2 3 4 5 6 7 8 9 10 11 12 13 |
Function addFilePermission ($FileName, [string]$ACLUserName, [string]$Permission, [string]$Allow_Deny){ if ((Test-Path $FileName) -eq $True) { $file = Get-ChildItem $FileName $acl = $file.GetAccessControl() $accessRule = New-Object System.Security.AccessControl.FileSystemAccessRule ("$ACLUserName","$Permission","$Allow_Deny") $acl.AddAccessRule($accessrule) $file.SetAccessControl($acl) } else { Write-Host "The system cannot find the file specified." } } addFilePermission "fileName.txt" "olie" "FullControl" "Allow" |