using powershell to set folder permission recursively for a user
We can use icacls to set folder permission for a user by using the following command. The /t option does this for folder and subfolders (recursive)
icacls "C:\Path\To\Your\Folder" /grant "Username:(OI)(CI)(M)" /T
Another option would be to use:
$folder = "C:\MyFolder" $acl = Get-Acl $folder $rule = New-Object System.Security.AccessControl.FileSystemAccessRule("JohnDoe", "Modify",
"ContainerInherit, ObjectInherit", "None", "Allow") $acl.SetAccessRule($rule) # Apply recursively Get-ChildItem -Path $folder -Recurse | ForEach-Object { $itemAcl = Get-Acl $_.FullName $itemAcl.SetAccessRule($rule) Set-Acl -Path $_.FullName -AclObject $itemAcl }
Comments