We have a lot of folders with the following permissions:
PS C:\> icacls.exe C:\Temp\Test
C:\Temp\Test BUILTIN\Administrators:(OI)(CI)(F)
NT AUTHORITY\SYSTEM:(OI)(CI)(F)
DOMAIN\USER:(OI)(IO)(RX)
DOMAIN\USER:(CI)(RX)
We would like to replace the two permissions from DOMAIN\USER to one with (OI)(CI)(RX).
To achive that, we used icacls.exe /grant:r. Unfortunately the :r parameter does not work.
PS C:\> icacls.exe --% C:\Temp\Test /grant:r DOMAIN\USER:(OI)(CI)(RX)
PS C:\> icacls.exe C:\Temp\Test
C:\Temp\Test BUILTIN\Administrators:(OI)(CI)(F)
NT AUTHORITY\SYSTEM:(OI)(CI)(F)
DOMAIN\USER:(OI)(IO)(RX)
DOMAIN\USER:(CI)(RX)
DOMAIN\USER:(OI)(CI)(F)
As you can see, the permission was added and not replaced.
Is there a way to replace the permissions with icacls.exe?
cacls.exeprovides the parameter/Pto achieve the replacement (see here).This one would work but then I struggled about the special permissions (
DOMAIN\USER2:(OI)(CI)(IO)(M))So I wrote some PowerShell code to achieve the same with
icacls.exe.Before granting the new explicit permission, the old one will be removed with
/remove:g.