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
Thank you farismalaeb.
The script worked. I was able to get the parent for the child items and set the permissions.
-- Does the below script looks good. As the permissions section is in a loop, just wanted to make sure, i am not redoing the same thing again and again.
-- Is there a way to print the permissions before and after enabling the inheritance to know what permissions have changed ?
$the_shares = ('C:\OIMShare\abc\', 'C:\OIMShare\abc1\','C:\OIMShare1\def\','C:\OIMShare2\ghi\')
$allFolders=Get-ItemProperty -Path $the_shares
Write-Host "The Parent is " -ForegroundColor Green -NoNewline
$allFolders.Parent.Name
foreach ($Folder in $allFolders){
$Permission=get-acl -Path $Folder.FullName
$Permission.SetAccessRuleProtection($False,$true)
Set-Acl -Path $Folder.FullName -AclObject $Permission
}
Thank you very much for all you guidance
Everything seems fine, and I always recommend trying things before applying it in production, what might seems to be fine might not be OK with you, so its always better to try 🙂
and yes you can get the current permission by running the following
Get-Acl -Path C:\AttendanceReport\ | select path,access -ExpandProperty Access
there is a more complicated way, which will provide a cleaner output, but you just need this for reference, so enjoy you day and the script
-----------------------------------
If everything is fine, please select one of the response and click on Best Response 🙂
Thanks
- suren424Oct 11, 2020Copper Contributor
Thank youfarismalaeb for all the help and guidance.