FN-GM Posted August 27, 2013 Posted August 27, 2013 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 Posted August 27, 2013 Posted August 27, 2013 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
pcstru Posted August 27, 2013 Posted August 27, 2013 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.
FN-GM Posted August 28, 2013 Author Posted August 28, 2013 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")
ascott2 Posted September 2, 2013 Posted September 2, 2013 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.
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now