+ 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,038
    Thank Post
    888
    Thanked 1,727 Times in 1,490 Posts
    Blog Entries
    12
    Rep Power
    453

    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
    181
    Thank Post
    18
    Thanked 37 Times in 29 Posts
    Rep Power
    20
    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,118
    Thank Post
    273
    Thanked 836 Times in 628 Posts
    Rep Power
    332
    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,038
    Thank Post
    888
    Thanked 1,727 Times in 1,490 Posts
    Blog Entries
    12
    Rep Power
    453
    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
    181
    Thank Post
    18
    Thanked 37 Times in 29 Posts
    Rep Power
    20
    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, 04:42 PM
  2. Replies: 5
    Last Post: 12th January 2007, 09:26 PM
  3. Folder Permissions
    By wesleyw in forum Windows
    Replies: 6
    Last Post: 9th January 2007, 08:25 PM
  4. DPS Folder Permissions
    By ajbritton in forum ICT KS3 SATS Tests
    Replies: 2
    Last Post: 18th December 2006, 11:09 AM
  5. Replies: 15
    Last Post: 12th October 2006, 09: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
  •