用 Get-Acl 和 Set-Acl 查看/修改 ACL

基于对象的 NTFS 权限管理——以结构化数据读取 ACE,再用 Set-Acl 写回修改后的安全描述符。

Windows文件权限PowerShell中风险
运行 (Get-Acl <路径>).Access | Format-Table 列出权限条目;修改对象后交给 Set-Acl 生效。

01命令

命令
$ (Get-Acl 'C:\Shared\Reports').Access | Format-Table IdentityReference, FileSystemRights, AccessControlType, IsInherited

02作用说明

Get-Acl 返回 .NET 的 DirectorySecurity/FileSecurity 对象,其 .Access 集合提供类型化字段(身份、权限、允许/拒绝、继承),不像 icacls 那样是纯文本。典型写法:$acl = Get-Acl $path; $acl.SetAccessRule(...); Set-Acl $path $acl,还能据此把一个目录的安全配置克隆给另一个目录。对注册表键同样适用(RegistrySecurity 提供程序)。

03风险

风险中风险
使用条件PowerShell; administrator rights to modify ACLs
!注意: Set-Acl 应用的是整个描述符而非差异——若拿旧对象写入,会抹掉期间被别人改动的权限;写入前务必重新执行 Get-Acl。

04撤销

✓无需撤销——该命令不会改变持久状态。

05来源

  • Get-Acl - PowerShell
    SS64 · technical · 2026-09-17
    依据: SS64 shows Get-Acl piped to Select-Object/Format-Table to list ACEs, and saving a descriptor with $acl | Set-Acl.
  • Get-Acl | Microsoft Learn
    Microsoft · vendor-doc · 2026-09-17
    依据: Microsoft documents Get-Acl returning a security descriptor object with an Access collection, and the paired Set-Acl for applying modified descriptors.

最后验证: 2026-09-17 · 分类: 文件与文件夹

06相关方案