Is there a better / easier way to set permissions on a Windows folder from the command line?
I am using powershell, get-acl and set-acl.
# Set permissions on a folder using powershell, get-acl and set-acl.
# make directory before settings permissions. setting permissions code creates file.
# if the user has no permissions on the folder run this script in a window with admin privileges.
# windows 10
# powershell 5
# change zpath and zuser
$zpath="F:\Users\Default\Documents\_NOTEPAD++ AUTOBACKUP"
$zuser="_9doug"
If(!(test-path $zpath)){New-Item -ItemType directory -Path $zpath | Out-Null}
$Acl = Get-Acl $zpath
$Ar = New-Object System.Security.AccessControl.FileSystemAccessRule($zuser, "FullControl", "ContainerInherit,ObjectInherit", "None", "Allow")
$Acl.SetAccessRule($Ar)
Set-Acl $zpath $Acl
exit 6 1 Answer
Windows 10 64-bit.
Use icacls. Does not require admin privileges if the user does not exist on the object.
Grant User Full Permissions:
icacls "%userprofile%\Documents\021219" /inheritance:d /grant:r %username%:(OI)(CI)F /TRemove a user:
icacls "%userprofile%\Documents\021219" /remove %UserName%Help:
icalcs /?
Grant user full permissions from the command line.
Remove user from the command line.