我正在尝试应用在Windows安全设置的“高级”标签中定义的NTFS权限。一个ACL $Rule
用于This folder only
,另一个用于Subfolders and files only
。
权限经过大量修改,如下所示:
(Get-Acl 'L:\Test\Beez\RAPJOUR\Appels List\Correct').Access
FileSystemRights : FullControl
AccessControlType : Allow
IdentityReference : BUILTIN\Administrators
IsInherited : False
InheritanceFlags : ContainerInherit, ObjectInherit
PropagationFlags : None
FileSystemRights : CreateFiles, AppendData, DeleteSubdirectoriesAndFiles, ReadAndExecute, Synchronize
AccessControlType : Allow
IdentityReference : Domain\Dirk
IsInherited : False
InheritanceFlags : None
PropagationFlags : None
FileSystemRights : DeleteSubdirectoriesAndFiles, Modify, Synchronize
AccessControlType : Allow
IdentityReference : Domain\Dirk
IsInherited : False
InheritanceFlags : ContainerInherit, ObjectInherit
PropagationFlags : InheritOnly
这是我用来应用权限的一段代码。在这种情况下,必须在Change
部分中定义:
$f = 'L:\Test\Beez\RAPJOUR\Appels List\Wrong'
$ADobject = 'Domain\User'
$acl = Get-Acl $f
$Grant = 'Change'
# Remove user/group first
$rule = New-Object system.security.AccessControl.FileSystemAccessRule("$ADobject","Read",,,"Allow")
$acl.RemoveAccessRuleAll($rule)
# Add read permissions
if ($Grant -eq 'ReadAndExecute') {
$rule = New-Object System.Security.AccessControl.FileSystemAccessRule("$ADobject", "ReadAndExecute", "ContainerInherit, ObjectInherit", "None", "Allow")
}
if ($Grant -eq 'Change') {
$rule = New-Object System.Security.AccessControl.FileSystemAccessRule("$ADobject", "Modify", "ContainerInherit, ObjectInherit", "Synchronize", "Allow DeleteSubdirectoriesAndFiles")
$acl.AddAccessRule($rule)
$rule = New-Object System.Security.AccessControl.FileSystemAccessRule("$ADobject", "AppendData", "ContainerInherit, ObjectInherit", "ReadAndExecute","Synchronize", "Allow CreateFiles","DeleteSubdirectoriesAndFiles")
}
if ($Grant -eq 'Modify') {
$rule = New-Object System.Security.AccessControl.FileSystemAccessRule("$ADobject", "Modify", "ContainerInherit, ObjectInherit", "None", "Allow")
}
if ($Grant -eq 'FullControl') {
$rule = New-Object System.Security.AccessControl.FileSystemAccessRule("$ADobject", "FullControl", "ContainerInherit, ObjectInherit", "None", "Allow")
}
if ($Grant -eq 'ListFolderContents') {
$rule = New-Object System.Security.AccessControl.FileSystemAccessRule("$ADobject", "ReadAndExecute", "ContainerInherit", "None", "Allow")
}
$acl.AddAccessRule($rule)
Set-Acl $f $acl
我似乎无法正确理解语法..感谢您的帮助。
感谢post我已经找到了这个部分:
"ContainerInherit, ObjectInherit", "InheritOnly"
"None", "InheritOnly"
答案 0 :(得分:9)
Windows中的对象访问权限是通过Access Control Lists(ACL)控制的,ACL基本上由Access Control Entries(ACE)列表组成。每个ACE都是一组属性,用于控制是授予还是拒绝访问,ACE应用于谁,ACE是否从父对象继承,以及是否应由子对象继承。
如果您查看FileSystemAccessRule
类的文档,您会看到“完整”构造函数需要5个参数:
IdentityReference
/ String
:标识ACE适用的受托者(用户,组,计算机......)的对象或字符串。FileSystemRights
:要授予或拒绝的实际permissions。InheritanceFlags
:用于控制哪些对象类型从此对象继承权限的标志(容器,叶对象或无)。PropagationFlags
:用于控制propagation权限的标志。标志InheritOnly
使当前对象免于接收ACE。标志NoPropagateInherit
将继承限制为直接子对象。AccessControlType
:ACE的type(允许或拒绝)。现在,如果您想为给定的受托者分配多个访问权限,您可以使用单个ACE执行此操作:
$acl = Get-Acl $path
$ace1 = New-Object Security.AccessControl.FileSystemAccessRule 'DOMAIN\user',
'ListDirectory', 'ContainerInherit, ObjectInherit', 'InheritOnly',
'Allow'
$acl.AddAccessRule($ace1)
$ace2 = New-Object Security.AccessControl.FileSystemAccessRule 'DOMAIN\user',
'ReadAttributes', 'ContainerInherit, ObjectInherit', 'InheritOnly',
'Allow'
$acl.AddAccessRule($ace2)
...
或者以逗号分隔的字符串形式提供权限:
$acl = Get-Acl $path
$ace = New-Object Security.AccessControl.FileSystemAccessRule 'DOMAIN\user',
'ListDirectory, ReadAttributes, ...', 'ContainerInherit, ObjectInherit',
'InheritOnly', 'Allow'
$acl.AddAccessRule($ace)
但请注意,您无法使用相同的ACE授予和拒绝权限。如果要拒绝特定的访问权限,则需要使用单独的ACE:
$acl = Get-Acl $path
$ace1 = New-Object Security.AccessControl.FileSystemAccessRule 'DOMAIN\user',
'Modify', 'ContainerInherit, ObjectInherit', 'InheritOnly',
'Allow'
$acl.AddAccessRule($ace1)
$ace2 = New-Object Security.AccessControl.FileSystemAccessRule 'DOMAIN\user',
'CreateDirectories', 'ContainerInherit, ObjectInherit', 'InheritOnly',
'Deny'
$acl.AddAccessRule($ace2)
...
另请注意,显式权限优先于继承权限,Deny
优先于Allow
。
答案 1 :(得分:2)
你知道当你在解决世界问题时会如何发展。发布问题的那一刻,你会在5分钟后找到答案......
感谢Frode F.对另一个问题的回答,我找到了解决自己问题的方法。我必须复制FileSystemRights
中$Correct.Access
行的输出并将其粘贴到Array
中,如下所示:
$rule = New-Object System.Security.AccessControl.FileSystemAccessRule("$ADobject", @("CreateFiles", "AppendData", "DeleteSubdirectoriesAndFiles"," ReadAndExecute", "Synchronize"), "None", "InheritOnly", "Allow") # This folder only
$acl.AddAccessRule($rule)
$rule = New-Object System.Security.AccessControl.FileSystemAccessRule("$ADobject", @("DeleteSubdirectoriesAndFiles", "Modify", "Synchronize"), "ContainerInherit, ObjectInherit", "InheritOnly", "Allow") # Subfolders and files only