I am trying to remove network folder permission recently, below script is working normally on the most of folders.
Here is my scenario:
1. I was generated a folder report including folder path, object name and permission. (ignore domain pls)
2. I have disabled inherit from parent by using below script and it works:
$acl = Get-Acl -Path $Path
$acl.SetAccessRuleProtection($True,$True)
Set-Acl -Path $Path -AclObject $acl
3. To remove folder access, i will use below script and it is working normally on the most of folders:
$AccessRule = New-Object System.Security.AccessControl.FileSystemAccessRule($Obj,$Access,,,"Allow")
$acl = Get-Acl $Path $acl.RemoveAccessRuleAll($AccessRule)
Set-Acl -Path $Path -AclObject $acl
4. Somehow i cannot remove an access from a folder, after manual checking, the folder has been disabled inherit from parent by using #2 script.
5. After failed to remove access by script, i try to remove it by manual, and it works.
6. There have over than 100,000+ access have to remove but unfortunately above script is not working for those folders, and those folders has been disabled inherit from parent.
7. I was tried to create the same access to the same folder by using below script:
$acl = Get-Acl $Path
$args = "$Obj","ReadAndExecute","ContainerInherit,ObjectInherit","None","Allow"
$AccessRule = New-Object System.Security.AccessControl.FileSystemAccessRule $args
$acl.SetAccessRule($AccessRule)
$acl | Set-Acl $Path
After creation, it is showing the two same access in the folder.
8. After that i use the remove script #3 again, and then only 1 access exists now. (The new added access has removed but the same old access still remain)
9. I have checked the folder access by using below script, all the words is exactly same as #7 $AccessRule, i run #7 script again but the access still remain and nothing changed.
$acl = Get-Acl $Path
$acl.Access
Question:
How can i remove folder access in this scenario? Or what should i go to check by using PowerShell?