Powershell: Combine ContainerInherit and ObjectInherit in FileSystemAccessRule? Powershell: Combine ContainerInherit and ObjectInherit in FileSystemAccessRule? powershell powershell

Powershell: Combine ContainerInherit and ObjectInherit in FileSystemAccessRule?


You can merge them using -bor (analogous to | in other languages). Parsing it from a string using a comma as shown in the other answer also works.

I also corrected your sample syntax and this sample should work.

$if=[Security.AccessControl.InheritanceFlags]$fsr=[Security.AccessControl.FileSystemRights]$pf=[Security.AccessControl.PropagationFlags]$flags = [Security.AccessControl.InheritanceFlags]($if::ContainerInherit -bor $if::ObjectInherit)$ar = new-object Security.AccessControl.FileSystemAccessRule ((New-Object System.Security.Principal.NTAccount($user)),$fsr::FullControl, $flags, $pf::InheritOnly, "Allow")

But even simpler is to use strings only:

new-object Security.AccessControl.FileSystemAccessRule ($user, "FullControl", "ContainerInherit,ObjectInherit", "InheritOnly", "Allow")


I'm not in front of a computer but try this:

[System.Security.AccessControl.InheritanceFlags]'ContainerInherit,ObjectInherit'