Forum Discussion
Getting a parent's parent for a folder using power shell
- Oct 17, 2020
the script seems to be working,
I try it on my side and the result was correct, good job.
$Permission.SetAccessRuleProtection($False,$true) Set-Acl -Path $allFolders.FullName -AclObject $Permission
In the first line and as the $Permission is holding the folder ACL information, there is one of the methods called SetAccessRuleProtection, you can find all other methods and properties by using $Permission | Get-Member.
The SetAccessRuleProtection accepts 2 input IsProtected and PreservedInheritance
SetAccessRuleProtection (bool isProtected, bool preserveInheritance);
IsProtected: Type is Bool ($True/$false) , $False= Enable Inheritance
PreservedInheritance : This parameter is actually ignored as the IsProtected is set to false
Thanks
-------------------------
Feel free to respond and request more information, if you find the answer that satisfy your need, Please make sure to mark it as Best Response and like the other.
Thanksfarismalaeb .
I tested the script few more times and yes it is not inheriting the permissions from parents parent.
So, will the below logic work ?
If the parent length is one, set the permission on parent to inherit from it's parent and then set the homefolder to inherit from it's parent.
Example :
HomeFolder : C:\OIMShare2\b\test\
Here the 'test' parent would be 'b'. so, inherit the permission from OIMShare2 to 'b' and after that set the permissions on 'test' to inherit from 'b'.
$the_shares = 'C:\OIMShare2\b\test\'
$allFolders=Get-ItemProperty -Path $the_shares
if (($allFolders.Parent.Name).Length -eq 1){
Write-Host "My Length is Only 1"
Write-Host "Setting the permissions of" $allfolders.Name "based on" $allfolders.Parent.Parent.Name
$Permission=get-acl -Path $allfolders.Parent.Parent.FullName
$Permission.SetAccessRuleProtection($False,$true)
Set-Acl -Path $allfolders.FullName -AclObject $Permission
}
Else{
Write-Host "The Parent Length is longer than 1"
Write-Host "Setting the permissions of" $allfolders.Name "based on" $allfolders.Parent.Name
$allFolders.Parent.Name
$Permission=get-acl -Path $allfolders.Parent.FullName
$Permission.SetAccessRuleProtection($False,$true)
Set-Acl -Path $allfolders.FullName -AclObject $Permission
}
Thanks in advance
Let me ask u on more question
This is Grandfather, Father, son relation
This should go in order
Maybe ibam asking the question again, but i am a bit confused.
Do u want to enable inherent in all the chain or u want to copy the permission?!
- suren424Oct 13, 2020Copper Contributorfarismalaeb
I would like enable inheritance so that it would get all the permissions.
But, What is the difference between enable inherent in all the chain or u copying the permission?
Thank you,