Forum Discussion
Powershell script to enable inheritance for the folders created in NTFS share
- Sep 30, 2020
You can use this example
$x=Get-ItemProperty -Path C:\MyFolder\123\456 Write-Host "The Parent is " -ForegroundColor Green -NoNewline $x.Parent.Name
if the answer fulfill your needs, please don't forget to click on Best Response and give a like 🙂
Thanks
Try this
$path='\\SharePath\Whatever'
$Permission=get-acl -Path $path
$Permission.SetAccessRuleProtection($False,$true)
Set-Acl -Path $path -AclObject $Permission
#https://docs.microsoft.com/en-us/dotnet/api/system.security.accesscontrol.objectsecurity.setaccessruleprotection?view=dotnet-plat-ext-3.1
This will enable inheritance on a folder
- suren424Sep 24, 2020Copper Contributor
Thanks for the quick response farismalaeb
I was doing some research and network share folder we need to have 'NTFSSecurity ' powershell module. Do i have to use cmdlets from 'NTFSSecurity' module or the one you shared works fine too.
I used this enable inheritance for 'abc' folder, but it's not enabling inheritance for the child items in the 'abc' holder. The same goes with child items in the parent folder 'C:\Share'. How to enable inheritance for child items too. I want to do this for all the folders that gets created newly on a daily basis.
Thanks in advance.
Get-Item C:\Share\abc\ | Enable-NTFSAccessInheritance
- farismalaebSep 24, 2020Iron Contributor
Regardless,
The Modules are make to ease and make common tasks easier and possible.
Have you tried the code I wrote,
Give it a try on a test folder and see the result, I test it from my side and its working fine, this is a native code, so no need for any module or anything, just copy and paste and thats it.
Replace the Value or the $Path with any folder and give it a try. if it work (and should) you can add it with a foreach loop. Just try the code on a test folder and post the result back
- suren424Sep 25, 2020Copper Contributor
Thank you farismalaeb
When i tried the below script , it didn't set enable inheritance for the child items in 'OIMShare' folder.
$path='\\WINDOWS-2S9Q\OIMShare\'
$Permission=get-acl -Path $path
$Permission.SetAccessRuleProtection($False,$true)
Set-Acl -Path $path -AclObject $PermissionBut, it worked when i ran this script.
$path='\\WINDOWS-2S9QPLV\OIMShare\abc\'
$Permission=get-acl -Path $path
$Permission.SetAccessRuleProtection($False,$true)
Set-Acl -Path $path -AclObject $PermissionWe have lot parent folders like 'OIMShare' (OIMShare1, OIMShare2,....) which many child items in it.
Thanks in advance.