Modify User Permissions using Powershell

Simon Eastwood 26 Reputation points
2022-03-18T17:17:08.49+00:00

I am new to PowerShell and I am trying to add a local user called 'Tree' with read-only and list permissions to all files and folders in a directory on my F:\ drive and force the permissions to propagate and not change any existing permissions

Windows Server PowerShell
Windows Server PowerShell
Windows Server: A family of Microsoft server operating systems that support enterprise-level management, data storage, applications, and communications.PowerShell: A family of Microsoft task automation and configuration management frameworks consisting of a command-line shell and associated scripting language.
5,462 questions
0 comments No comments
{count} vote

Accepted answer
  1. MotoX80 32,911 Reputation points
    2022-03-18T21:42:38.05+00:00

    You can do it with icacls.exe.

    icacls.exe F:\ /grant "Tree:(OI)(CI)(RX)"
    

    Or with Powershell cmdlets.

    $Folder = 'F:\'
    $ACL = Get-Acl  $Folder
    $ACL_Rule = new-object System.Security.AccessControl.FileSystemAccessRule ('Tree', "ReadAndExecute",”ContainerInherit,ObjectInherit”,”None”,”Allow”)
    $ACL.SetAccessRule($ACL_Rule)
    Set-Acl -Path $Folder -AclObject $ACL 
    

    If you have folders that do not inherit permissions from their parent folder, the access will not be applied to them.

    As always, try this on a test folder first.


0 additional answers

Sort by: Most helpful