tags:

views:

137

answers:

2

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
} 
A: 

I think your answer can be found on this page. From the page:

This Folder, Subfolders and Files:

InheritanceFlags.ContainerInherit | InheritanceFlags.ObjectInherit 
PropagationFlags.None
David Gladfelter
Thanks - works perfectly!
Tim AtLee
+1  A: 

Just because you're in PowerShell don't forgot about good ol' exes. Sometimes they can provide the easiest solution e.g.:

icacls.exe $folder /grant 'domain\user:(OI)(CI)(M)'
Keith Hill
Yeah, I almost solved the problems with a DOS batch file and icacls or setacl, but trying to learn powershell.. best way to learn is by solving a problem with it, etc.
Tim AtLee
I understand. OTOH I've been using PowerShell for > 5 years now and I don't hesitate to drop back to an EXE if it is significantly easier than the PowerShell equivalent. IOW there's plenty to learn in PowerShell - some more worthwhile than others. :-)
Keith Hill