icacls 从 ACL 中删除所有组

Blu*_*luz 2 acl powershell-2.0

我正在尝试使用 icacls 修改文件上的 ACL。我希望该文件由管理员拥有并且只能由管理员访问。我找到了如何使管理员成为文件的所有者,并且我知道如何从安全列表中删除组,但我不知道如何删除除管理员组之外的所有组(如果我不知道该组的名称)其他团体。

我正在寻找一种方法来告诉 Windows 我只想让管理员访问该文件并删除任何其他用户/组(如果有)。

我尝试使用通配符,但它不起作用。

这是我的脚本:

$domain     = [Environment]::UserDomainName
$user       = [Environment]::UserName
icacls $myinvocation.mycommand.path /setowner "$domain\$user" /T
icacls $myinvocation.mycommand.path /grant "$domain\$user"

icacls $myinvocation.mycommand.path
Run Code Online (Sandbox Code Playgroud)

RB.*_*RB. 5

理论上,您可以:r在授予后使用(请参阅文档)。然而,实际上我无法完成这项工作。我认为:r意思是“仅替换指定用户的权限”。

我已经在 Powershell 中测试了以下解决方案,但它运行良好。

# Reset the folder to just it's inherited permissions
icaclsname c:\temp\test /reset 

# Then, disable inheritance and remove all inherited permissions
icacls c:\temp\test /inheritance:r

# Note the :r after grant. It's not now needed, but I've left it in anyway.
# Permissions replace previously granted explicit permissions.
# Also note the :F, where : is escaped with `. This grants FULL CONTROL.
# You can replace F with whatever level of control is required for you.
icacls c:\temp\test /grant:r $domain\$user`:F
Run Code Online (Sandbox Code Playgroud)