加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 综合聚焦 > 服务器 > Windows > 正文

windows – 使用powershell删除文件夹上的所有ACL

发布时间:2020-12-14 04:20:20 所属栏目:Windows 来源:网络整理
导读:我是Power Shell脚本的新手(自从我开始学习powershell以来将近一个月). 我目前正在使用powershell 2.0编写一个脚本来清理文件夹NTFS ACL.我想删除除管理员之外的每个acl. 我的问题是我找不到删除每个非管理员的acl的方法,而不知道它们. 所以我来到这里寻求po
我是Power Shell脚本的新手(自从我开始学习powershell以来将近一个月).

我目前正在使用powershell 2.0编写一个脚本来清理文件夹NTFS ACL.我想删除除管理员之外的每个acl.

我的问题是我找不到删除每个非管理员的acl的方法,而不知道它们.

所以我来到这里寻求powershell pro.

此代码删除acl:
$acl = Get-Acl remote_servershare_folderHAL.9000
$acl.Access | %{$acl.RemoveAccessRule($_)}

此代码添加管理员acl:

#BUILTIN administrator

$acl = Get-Acl remote_servershare_folderHAL.9000
$permission  = "BUILTINAdministrators","FullControl","ContainerInherit,ObjectInherit","None","Allow"
$accessRule = New-Object System.Security.AccessControl.FileSystemAccessRule $permission
$acl.SetAccessRule($accessRule)
Set-Acl remote_servershare_folderHAL.9000 $acl

#Domain controller administrator

$acl = Get-Acl remote_servershare_folderHAL.9000
$permission  = "DOMAINCONTROLLERAdministrators","Allow"
$accessRule = New-Object System.Security.AccessControl.FileSystemAccessRule $permission
$acl.SetAccessRule($accessRule)
Set-Acl remote_servershare_folderHAL.9000 $acl

希望这会帮助别人:)

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读