PowerShell To Set Folder Permissions

前端 未结 5 831
旧时难觅i
旧时难觅i 2020-12-05 12:35

I am trying to use the \"default\" options in applying folder permissions; by that, I mean that using the \"Full Controll, Write, Read, etc\" in the \'Properties\' for a fol

5条回答
  •  萌比男神i
    2020-12-05 13:17

    Specifying inheritance in the FileSystemAccessRule() constructor fixes this, as demonstrated by the modified code below (notice the two new constuctor parameters inserted between "FullControl" and "Allow").

    $Acl = Get-Acl "\\R9N2WRN\Share"
    
    $Ar = New-Object System.Security.AccessControl.FileSystemAccessRule("user", "FullControl", "ContainerInherit,ObjectInherit", "None", "Allow")
    
    $Acl.SetAccessRule($Ar)
    Set-Acl "\\R9N2WRN\Share" $Acl
    

    According to this topic

    "when you create a FileSystemAccessRule the way you have, the InheritanceFlags property is set to None. In the GUI, this corresponds to an ACE with the Apply To box set to "This Folder Only", and that type of entry has to be viewed through the Advanced settings."

    I have tested the modification and it works, but of course credit is due to the MVP posting the answer in that topic.

提交回复
热议问题