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.Nameif the answer fulfill your needs, please don't forget to click on Best Response and give a like 🙂
Thanks
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
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 $Permission
But, 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 $Permission
We have lot parent folders like 'OIMShare' (OIMShare1, OIMShare2,....) which many child items in it.
Thanks in advance.
- farismalaebSep 25, 2020Iron Contributor
Yes sure it wont work in all folder as its not part of a loop
This is the full code
$allFolders=Get-ChildItem -Path C:\MySource -Directory -Recurse
foreach ($Folder in $allFolders){
$Permission=get-acl -Path $Folder.FullName
$Permission.SetAccessRuleProtection($False,$true)
Set-Acl -Path $Folder.FullName -AclObject $Permission
}You only need to modify the path of the root and the script will do the same
- suren424Sep 25, 2020Copper Contributor
Thank youfarismalaeb
Your script worked. I tried improvising your script to include multiple shares, but it's throwing below error(attached screeshot). Am i missing anything in the script ?
Script :
$the_shares = ('\\WINDOWS-2S9QPLV\OIMShare\', '\\WINDOWS-2S9QPLV\OIMShare1\')
$allFolders=Get-ChildItem -Path $the_shares -Directory -Recurse
foreach ($Folder in $allFolders){
$Permission=get-acl -Path $Folder.FullName
$Permission.SetAccessRuleProtection($False,$true)
Set-Acl -Path $Folder.FullName -AclObject $Permission
}- farismalaebSep 26, 2020Iron Contributor
The error is stating that the path not found.
Make sure that you have the access to that directory and/or its really exist \\Windows-2S9QPLV\OIMShare1