How to replace permissions and everything inside with icacls on Windows Server 2012?

Solution 1:

As mentionned is comments, you also have to use the /inheritance:r switch to remove inherited permissions.

/grant:r only removes explicit permissions.

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

To also grant SYSTEM :

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

Solution 2:

The parameter /grant:r didn't work for me. I had to use /reset to revert permissions to inherintance only and then remove the inherited permissions. Don't forget to change subdirectories with /t flag.