- 1 year ago
Powershell ICACLS to change permissions on a file
Comment
1 / 1
In PowerShell, you can use the icacls
command to change permissions on a file or directory. icacls
is a Windows command-line utility that allows you to view and modify security settings on files and directories.
The basic syntax of the icacls
command is as follows:
powershellicacls <path> /grant:<user or group>:<permissions>
<path>
: The path to the file or directory for which you want to change permissions.<user or group>
: The name of the user or group for which you want to grant permissions.<permissions>
: The permissions you want to grant to the user or group. This can be a combination ofF
(Full control),M
(Modify),RX
(Read and execute),R
(Read),W
(Write), etc.
Here are some examples of using icacls
in PowerShell to change permissions on a file:
Grant Full Control to a User:
powershellicacls "C:\path\to\file.txt" /grant:User1:(F)
Grant Modify and Read permissions to a Group:
powershellicacls "C:\path\to\file.txt" /grant:Group1:(M,RX)
Grant Write permission to Everyone:
powershellicacls "C:\path\to\file.txt" /grant:Everyone:(W)
Please note the following points:
- To use
icacls
, you need administrative privileges, so run PowerShell as an administrator. - The permissions are case-sensitive, so use uppercase letters for permissions (e.g.,
F
,M
,RX
, etc.). - If you want to remove permissions, you can use the
/remove
option instead of/grant
. - Be cautious when modifying permissions, as incorrect settings may lead to security issues.
For more advanced usage and options, you can refer to the icacls
documentation by running icacls /?
in a PowerShell console or by checking the Microsoft documentation: https://docs.microsoft.com/en-us/windows-server/administration/windows-commands/icacls