Solved

PoweShell Script for Disabling Inheritance on Subfolders

Posted on 2014-11-04
6
415 Views
Last Modified: 2014-11-25
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.
0
Comment
Question by:GR JN
  • 3
  • 2
6 Comments
 
LVL 17

Expert Comment

by:lruiz52
ID: 40422767
0
 
LVL 28

Expert Comment

by:becraig
ID: 40422914
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
}

Open in new window

0
 

Author Comment

by:GR JN
ID: 40424171
Thanks just to confirm this will DISABLE inheritance on the child folders?
0
 
LVL 28

Expert Comment

by:becraig
ID: 40424566
Yes.

so the script will enumerate all child folders within the parent folder specified.
gci c:\parentfolder - recurse 

Open in new window


It will verify it is only running against folders
| where { $_.PsIsContainer }

Open in new window


Then for each folder it finds no matter how many levels deep it will disable inheritance.
$acl.SetAccessRuleProtection($true, $true)

Open in new window

If we want to limit recursion we can specify how many folders deep we go e.g.:
gci c:\parentfolder\*\*\*

Open in new window

will return two folders deep add an additional \*  for each level deeper you want to recurse.
0
 

Author Comment

by:GR JN
ID: 40424621
Thanks. I would only want to disable inheritance on the child folder but not the grandchildren. What would this syntax look like?
0
 
LVL 28

Accepted Solution

by:
becraig earned 500 total points
ID: 40424645
gci -Path c:\somefolder\* | ? { $_.PsIsContainer } | % {
	$acl = Get-Item $_ | get-acl
	$acl.SetAccessRuleProtection($true, $true)
	$acl | Set-Acl
}
                         

Open in new window

0

Join & Write a Comment

In this article, we will see the basic design consideration while designing a Multi-tenant web application in a simple manner. Though, many frameworks are available in the market to develop a multi - tenant application, but do they provide data, cod…
Is your Office 365 signature not working the way you want it to? Are signature updates taking up too much of your time? Let's run through the most common problems that an IT administrator can encounter when dealing with Office 365 email signatures.
This tutorial will walk an individual through the process of transferring the five major, necessary Active Directory Roles, commonly referred to as the FSMO roles to another domain controller. Log onto the new domain controller with a user account t…
This tutorial will walk an individual through the process of configuring their Windows Server 2012 domain controller to synchronize its time with a trusted, external resource. Use Google, Bing, or other preferred search engine to locate trusted NTP …

744 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

11 Experts available now in Live!

Get 1:1 Help Now