When I set a new filesystemaccess rule with powershell and set-acl, I set the inheritance flags to propagate to children and leaf objects
$acl.AddAccessRule((New-Object System.Security.AccessControl.FileSystemAccessRule(
"username","FullControl", "ContainerInherit, ObjectInherit", "None", "Allow")))
Set-Acl -path $filename -aclObject $acl
When I look at the permission in explorer.. in the security tab.. advanced.. the propagation is set correctly. But if I look at the children themselves, they do NOT show the new security rule.
If in explorer, I add another rule with a different SID.. and save it (without forcing the option to 'replace all child object permissions...'). Then both the manual, and the powershell rule shows up on the children. Its as if there is some sort of kickstart needed to cause the children to pick up the new propagated rule. What am I missing to make the child objects show the new rule added?
I have been scouring the internet and several StackOverflow questions trying to puzzle this out. I may not have the best solution, but I think it satisfies the question. According to my research, Powershell's
Set-Acl
just doesn't handle inheritance properly. The key to the code below is two things: theSystem.Security.AccessControl.DirectorySecurity
object and using the alternative method for setting the ACL$dir.SetAccessControl()
The children of the target folder (both folders and files) will successfully inherit the permissions attached to your target folder.Calling example:
Function: