+ Post New Thread
Results 1 to 5 of 5
Scripts Thread, Powershell - Folder Permissions in Coding and Web Development; I have some code that works in giving a user full control of a folder in powershell this is below. ...
  1. #1

    FN-GM's Avatar
    Join Date
    Jun 2007
    Location
    UK
    Posts
    16,323
    Thank Post
    903
    Thanked 1,802 Times in 1,551 Posts
    Blog Entries
    12
    Rep Power
    467

    Powershell - Folder Permissions

    I have some code that works in giving a user full control of a folder in powershell this is below. How do i change this is its "Read & execute", "List folder contents" & "read" please?

    Thanks

    $Ar = New-Object system.security.accesscontrol.filesystemaccessrule ($domuser,"FullControl","ContainerInherit, ObjectInherit","None","Allow")

  2. #2
    ascott2's Avatar
    Join Date
    Nov 2007
    Posts
    185
    Thank Post
    18
    Thanked 39 Times in 31 Posts
    Rep Power
    21
    Not tested but this should do it

    $folder_or_item = "C:\data\"
    $acl = Get-Acl $folder_or_item

    $rights =@("ReadAndExecute","Read","ListDirectory")

    foreach($right in $rights){
    $accessRule = New-Object System.Security.AccessControl.FileSystemAccessRule ($domuser,$right,"ContainerInherit, ObjectInherit","None","Allow")
    $acl.addaccessRule($accessrule)
    }
    Set-Acl $folder_or_item $acl

  3. #3


    Join Date
    May 2009
    Posts
    3,322
    Thank Post
    293
    Thanked 890 Times in 668 Posts
    Rep Power
    342
    Quote Originally Posted by FN-GM View Post
    I have some code that works in giving a user full control of a folder in powershell this is below. How do i change this is its "Read & execute", "List folder contents" & "read" please?

    Thanks

    $Ar = New-Object system.security.accesscontrol.filesystemaccessrule ($domuser,"FullControl","ContainerInherit, ObjectInherit","None","Allow")
    ascott2 I think has the gist. There's also a long list of rights attributes on technet.

  4. #4

    FN-GM's Avatar
    Join Date
    Jun 2007
    Location
    UK
    Posts
    16,323
    Thank Post
    903
    Thanked 1,802 Times in 1,551 Posts
    Blog Entries
    12
    Rep Power
    467
    So i dont have to add more lines i assume this would work? Thanks

    $Ar = New-Object system.security.accesscontrol.filesystemaccessrule ($domuser,@("ReadAndExecute","Read","ListDirectory "),"ContainerInherit, ObjectInherit","None","Allow")

  5. #5
    ascott2's Avatar
    Join Date
    Nov 2007
    Posts
    185
    Thank Post
    18
    Thanked 39 Times in 31 Posts
    Rep Power
    21
    Quote Originally Posted by FN-GM View Post
    So i dont have to add more lines i assume this would work? Thanks

    $Ar = New-Object system.security.accesscontrol.filesystemaccessrule ($domuser,@("ReadAndExecute","Read","ListDirectory "),"ContainerInherit, ObjectInherit","None","Allow")
    Unfortunately you can't add an array to filesystemaccessrule as it is only expecting a string( well technically a fileaccess object) so you need to add each permission type individually, that was why I had used a loop in my example.



SHARE:
+ Post New Thread

Similar Threads

  1. Student drop box (homework folder) permissions
    By ashdon in forum How do you do....it?
    Replies: 21
    Last Post: 8th October 2012, 05:42 PM
  2. Replies: 5
    Last Post: 12th January 2007, 10:26 PM
  3. Folder Permissions
    By wesleyw in forum Windows
    Replies: 6
    Last Post: 9th January 2007, 09:25 PM
  4. DPS Folder Permissions
    By ajbritton in forum ICT KS3 SATS Tests
    Replies: 2
    Last Post: 18th December 2006, 12:09 PM
  5. Replies: 15
    Last Post: 12th October 2006, 10:37 PM

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •