如何用Windows Server 2012上的icaclsreplace权限和一切内容?

使用Windows Server 2012 R2和Windows Server 2008 R2。

我有一个名为C:\temp\test的文件夹,我想要授予对SYSTEM和用户以及所有文件和子目录的访问权限,并删除其他的文件。 我试过这个命令,但所有现有的权限仍然存在:

现有的权限是:

 Access : NT AUTHORITY\SYSTEM Allow FullControl BUILTIN\Administrators Allow FullControl BUILTIN\Users Allow ReadAndExecute, Synchronize BUILTIN\Users Allow AppendData BUILTIN\Users Allow CreateFiles CREATOR OWNER Allow 268435456 

我想删除除SYSTEM以外的所有ACL,并添加<DOMAIN>\<USER>

我试过这个命令:

 icacls c:\temp\test /grant:r <DOMAIN>\<USER>:(OI)(CI)F /t processed file: c:\temp\test Successfully processed 1 files; Failed processing 0 files 

当我查看以后的权限时, <DOMAIN>\<USER>具有正确的权限,但其他所有权限都保留。 我想/grant:r取代所有的权限? 你知道什么命令我需要运行删除所有其他权限?

正如提到的是注释,您还必须使用/inheritance:r开关来删除inheritance的权限。

/grant:r只会删除显式权限。

 icacls c:\temp\test /inheritance:r /grant:r <DOMAIN>\<USER>:(OI)(CI)F /T 

还要授予SYSTEM

 icacls c:\temp\test /inheritance:r /grant:r <DOMAIN>\<USER>:(OI)(CI)F /grant:r SYSTEM:(OI)(CI)F /T 

/grant:r没有为我工作。 我必须使用/reset才能将权限恢复为仅inheritance,然后删除inheritance的权限。 不要忘记用/t标志来改变子目录。