Assign user ACL permissions to a folder and sub directory using powershell

Welcome Forums General PowerShell Q&A Assign user ACL permissions to a folder and sub directory using powershell

This topic contains 1 reply, has 2 voices, and was last updated by

 
Senior Moderator
3 weeks, 3 days ago.

  • Author
    Posts
  • #179943

    Participant
    Topics: 1
    Replies: 0
    Points: 11
    Rank: Member

    Hello,

    Using a powershell script, I would like to add read and execute permission to a folder and its sub directories.

    I user the following code:

    $path = "\\domain.com\users\users1\test54"
    $user = "test54@domain.com"
    $Rights = "Read, ReadAndExecute, ListDirectory"
    $InheritSettings = "Containerinherit, ObjectInherit"
    $PropogationSettings = "None"
    
    $RuleType = "Allow"
    
    $acl = Get-Acl $path
    $perm = $user, $Rights, $InheritSettings, $PropogationSettings, $RuleType
    $rule = New-Object -TypeName System.Security.AccessControl.FileSystemAccessRule -ArgumentList $perm
    $acl.SetAccessRule($rule)
    $acl | Set-Acl -Path $path
    

    However, when I execute this code (my account has admin level access), the ACL for this folder does not include the account test54.

    What needs to be done so that I can add the user with access rights Read /List/Execute to the ACL  of the specified folder?

    Thanks in advance!

    Mark

     

  • #179952

    Senior Moderator
    Topics: 8
    Replies: 1085
    Points: 3,651
    Helping Hand
    Rank: Community Hero

    Can yo try AddAccessRule() method.

You must be logged in to reply to this topic.