Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

PoweShell Script for Disabling Inheritance on Subfolders

Posted on 2014-11-04
6
Medium Priority
?
912 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 3
  • 2
6 Comments
 
LVL 17

Expert Comment

by:lruiz52
ID: 40422767
0
 
LVL 29

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
Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
LVL 29

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 29

Accepted Solution

by:
becraig earned 2000 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

Featured Post

Are You Ready for GDPR?

With the GDPR deadline set for May 25, 2018, many organizations are ill-prepared due to uncertainty about the criteria for compliance. According to a recent WatchGuard survey, a staggering 37% of respondents don't even know if their organization needs to comply with GDPR. Do you?

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Had a business requirement to store the mobile number in an environmental variable. This is just a quick article on how this was done.
In the absence of a fully-fledged GPO Management product like AGPM, the script in this article will provide you with a simple way to watch the domain (or a select OU) for GPOs changes and automatically take backups when policies are added, removed o…
In this video, we discuss why the need for additional vertical screen space has become more important in recent years, namely, due to the transition in the marketplace of 4x3 computer screens to 16x9 and 16x10 screens (so-called widescreen format). …
Exchange organizations may use the Journaling Agent of the Transport Service to archive messages going through Exchange. However, if the Transport Service is integrated with some email content management application (such as an antispam), the admini…
Suggested Courses

705 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