![](/img/trans.png)
[英]How to find all the empty subfolders inside the folder using powershell?
[英]How to remove all access rules from folder AND all subfolders using PowerShell?
我知道已针对特定文件夹回答了这个问题,但是我也想从所有子文件夹中删除一个用户。
我尝试设置继承和传播值以确保该设置被继承,但是无论我如何设置参数,它都仅适用于根目录。 (部分)我的代码如下所示:
$inherit = "ContainerInherit, ObjectInherit"
$propagation = "None"
$Acl=get-acl $o2
$Accessrule = New-Object system.security.AccessControl.FileSystemAccessRule($o1,"Read", $inherit, $propagation,"Allow")
$Acl.RemoveAccessRuleAll($Accessrule)
Set-Acl -Path $o2 -AclObject $Acl
请注意以下内容,它将删除ACL
使用前测试
我强烈建议您在使用以下驱动器之前,在单独的驱动器上使用完整的ACL进行ROBOCOPY。 如果有什么不对劲,您可以随时复制文件或ACL或同时复制两者。
好的,您可以从这里开始。 就像Ansgar所说的那样,您几乎遍历了文件夹列表,并为每个文件夹检索了每个ACL中的所有访问控制项(ACE)。
如果没有继承ACE,则将其删除。
更新为使用$ o1此版本中的ACE需要分配给$o1
定义的用户。
我还没有测试过,因此在释放地狱之前进行一些测试并逐步检查这些值。
$filepath = "<your drive letter>:"
$folders = @((get-item $filePath))
$folders += Get-ChildItem $filePath -Recurse | where { $_.PSIsContainer -ne $false }
Foreach ($folder in $folders)
{
$acl = Get-Acl -Path $folder.FullName
Foreach($access in $acl.access)
{
if ($access.isinherited -eq $false -and $access.IdentityReference.Value -eq $o1)
{
$acl.RemoveAccessRule($access)
}
}
Set-Acl -path $folder.fullname -aclObject $acl
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.