Jump to content
EduGeek EdSec 2026 is Go! 27th Oct in Derby! Join us for a day of EdTech security focused talks, networking, and an evening social ×

Recommended Posts

Posted

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")

Posted

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

Posted
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.

Posted

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")

Posted
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.

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 account

Sign in

Already have an account? Sign in here.

Sign In Now



×
×
  • Create New...