I am trying to mimic the action of right-clicking on a folder, setting "modify" on a folder, and having the permissions apply to the specific folder and subfolders and files.
I'm mostly there using Powershell, however the inheritance is only being set as "subfolders and files" instead of the whole "this folder, subfolders and files".
Is there some unlisted flag for System.Security.AccessControl.PropagationFlags that will set this properly?
Here's what I'm working with so far.
$Folders = Get-childItem c:\TEMP\
$InheritanceFlag = [System.Security.AccessControl.InheritanceFlags]::ContainerInherit -bor [System.Security.AccessControl.InheritanceFlags]::ObjectInherit
$PropagationFlag = [System.Security.AccessControl.PropagationFlags]::InheritOnly
$objType = [System.Security.AccessControl.AccessControlType]::Allow
foreach ($TempFolder in $Folders)
{
echo "Loop Iteration"
$Folder = $TempFolder.FullName
$acl = Get-Acl $Folder
$permission = "domain\user","Modify", $InheritanceFlag, $PropagationFlag, $objType
$accessRule = New-Object System.Security.AccessControl.FileSystemAccessRule $permission
$acl.SetAccessRule($accessRule)
Set-Acl $Folder $acl
}
Just because you're in PowerShell don't forgot about good ol' exes. Sometimes they can provide the easiest solution e.g.:
I think your answer can be found on this page. From the page:
Here's the MSDN page describing the flags and what is the result of their various combinations.
To have it apply the permissions to the directory, as well as all child directories and files recursively, you'll want to use these flags:
So the specific code change you need to make for your example is:
Here's some succinct Powershell code to apply new permissions to a folder by modifying it's existing ACL (Access Control List).
Each of the values in the
$permissions
variable list pertain to the parameters of this constructor for the FileSystemAccessRule class.Courtesy of this page.
Here's a table to help find the required flags for different permission combinations.
So, as David said, you'll want