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


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")
  • I did have to tweak it a bit for my own script but it was indeed what I needed to know. Thanks! Feb 27 '12 at 13:37

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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