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
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
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
- suren424Sep 30, 2020Copper Contributor
Thank you farismalaeb .
The script worked after changing the path from '\\Windows-2S9QPLV\OIMShare1 to C:\OIMShare1.
Quick question :
Is there a way to identify the parent folder if we provide the child items in the script.
Actually, we will provide the child items ('C:\OIMShare1\abc1\') in the script and it has identify the parent folder ('C:\OIMShare1\') and the child items need to inherit all the permissions for the parent.
Thanks in advance
- farismalaebSep 30, 2020Iron Contributor
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