Im trying to remove a group from a bunch of subfolders permission using powershell, but for some reason it doesnt apply to the subfolder, it oly runs and apply the changes to the main folder, here is the code. Can someone help?
$grupo = "PAULWURTH\Domain Users"
$dir = "C:\Robocopy\TESTE\userdata$"
$subfolder=Get-ChildItem -Path $dir -Directory -Recurse
foreach ($subfolder in $dir){
# Disable inherit
$acl = Get-ACL -Path $subfolder
$acl.SetAccessRuleProtection($True, $True)
Set-Acl -Path $subfolder -AclObject $acl
# Removes group permission
$acl = Get-Item $subfolder |get-acl
$acl.Access |where {$_.IdentityReference -eq $grupo} |%{$acl.RemoveAccessRule($_)}
$acl |Set-Acl
}