Rammy Charles
asked on
PoweShell Script for Disabling Inheritance on Subfolders
We are looking for a PowerShell script that will simply disable permission inheritance for every subfolder in a parent directory.
Any suggestions would be appreciated.
Any suggestions would be appreciated.
pipe your get child item into a where item equal a folder then do a foreach and reset the permission
gci -Path c:\somefolder -recurse | where { $_.PsIsContainer } | % {
$acl = Get-Item $_ | get-acl
$acl.SetAccessRuleProtection($true, $true)
$acl | Set-Acl
}
ASKER
Thanks just to confirm this will DISABLE inheritance on the child folders?
Yes.
so the script will enumerate all child folders within the parent folder specified.
It will verify it is only running against folders
Then for each folder it finds no matter how many levels deep it will disable inheritance.
so the script will enumerate all child folders within the parent folder specified.
gci c:\parentfolder - recurse
It will verify it is only running against folders
| where { $_.PsIsContainer }
Then for each folder it finds no matter how many levels deep it will disable inheritance.
$acl.SetAccessRuleProtection($true, $true)
If we want to limit recursion we can specify how many folders deep we go e.g.:
gci c:\parentfolder\*\*\*
will return two folders deep add an additional \* for each level deeper you want to recurse.
ASKER
Thanks. I would only want to disable inheritance on the child folder but not the grandchildren. What would this syntax look like?
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
http://jeffwouters.nl/index.php/2014/05/powershell-function-to-configure-inheritance-on-folders/