Take the 2-minute tour ×
Server Fault is a question and answer site for system and network administrators. It's 100% free, no registration required.

I have written two PowerShell scripts. One asks the user for a foldername. It creates a folder with that name, gives the user full control, gives the administrators group full control and strips the inherited rights, leaving only the user and administrators. The second script asks for a username and gives modify rights to that user in the new folder.

It works as intended except for one thing: when I create a file or folder in the newly created folder, it doesn't inherit those rights. I looked at the security tab, clicked advanced and edit (on the accounts), and found 2 things not as I want them:

  • The 'apply to' setting is 'this folder only'. When I manually set it to 'this folder, subfolder and files' it works as intended
  • The user created with the second script has the above, and the permissions box 'delete subfolders and files' is not ticked.

Adding the accounts revolves around these lines:

$Acl = Get-Acl $Folderpath
$Ar = New-Object system.Security.AccessControl.FileSystemAccessRule($user_account,"FullControl","Allow")
$Acl.Setaccessrule($Ar)
Set-Acl $Folderpath $Acl

$Folderpath is a variable set earlier pointing to the folder. $user_account is a variable set earlier containing the useraccount name.

My question:

Is there a way to have these accounts added to the folder permissions correctly (rights will be inherited, user has delete rights) or to correct it afterwards in the script?

share|improve this question

1 Answer 1

up vote 3 down vote accepted

Needs more inheritance flags; the constructor you're using to create the ACE by only passing three arguments doesn't specify how the ACE should inherit.

Try this:

$Ar = New-Object system.Security.AccessControl.FileSystemAccessRule($user_account, "FullControl", "ContainerInherit, ObjectInherit", "None", "Allow")
share|improve this answer
    
I did have to tweak it a bit for my own script but it was indeed what I needed to know. Thanks! –  Erwin Blonk Feb 27 '12 at 13:37

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.