我正在尝试在PowerShell中模拟我通常在Windows文件夹属性窗口中执行的操作:文件夹属性→Secutity→高级→权限→更改权限...
在该GUI中有
的勾选框PropagationFlag
= None
当您点击添加/编辑...按钮时,您有一个包含以下选项的下拉列表,InheritanceFlags
与每个选项对应的是什么?我已经填写了我通过实验找到的那些
None
ContainerInherit, ObjectInherit
ContainerInherit
ObjectInherit
与复选框对应的标志仅将此权限应用于此容器中的对象和/或容器?
我还确定这些PropagationsFlags
意味着:
我想知道如何为现有用户/群组添加额外权限,或者将额外的用户/群组添加到文件夹的权限中,并使用“此文件夹子文件夹和文件传播” “但不是”使用来自此对象的可继承权限替换所有子对象权限“以防有一个子目录有其他特殊权限,因为有充分理由,例如用户配置文件中的符号链接文件夹。
我目前正在处理的代码如下。最终,我将在多个域中的许多计算机上的许多不同文件夹上使用它,包括c:\users\{username}
中的用户配置文件
function check-permissions ( $folder ) {
$GroupName = "Domain Admins"
if ( -not (Test-Path -LiteralPath $folder) ) {
Write-Output "Cannot find $folder"
} else {
((get-acl -literalPath $folder).access).IdentityReference.Value |
findstr /i ($env:USERDOMAIN + "\"+ $GroupName) |
out-null
$result = $?
if ( -not $result ) {
write-output ($folder + ": adding permissions")
#adding new permissions
$colRights = [System.Security.AccessControl.FileSystemRights]"FullControl"
$InheritanceFlag = [System.Security.AccessControl.InheritanceFlags]::ContainerInherit, [System.Security.AccessControl.InheritanceFlags]::ObjectInherit
$PropagationFlag = [System.Security.AccessControl.PropagationFlags]::InheritOnly
$objType =[System.Security.AccessControl.AccessControlType]::Allow
$objUser = New-Object System.Security.Principal.NTAccount($env:USERDOMAIN + "\" + $GroupName)
$objACE = New-Object System.Security.AccessControl.FileSystemAccessRule ($objUser, $colRights, $InheritanceFlag, $PropagationFlag, $objType)
# output the ACE
$objACE | format-list *
#$objACL = Get-Acl -literalPath $folder # This gets the full security info but substitutes the different user as owner, which we don't want or it will overwrite the owner info with the wrong user when we use set-acl
$objACL = (Get-Item -literalPath $folder).GetAccessControl('Access')
if ( -not $? ) {
Write-Output ("Failed to get permissions on: " + $folder)
} else {
$objACL.AddAccessRule($objACE)
if ( $objACL ) { #objACL exists
#Set-ACL -literalPath ($folder) -AclObj $objACL # This tries to set the owner too
[System.IO.Directory]::SetAccessControl($folder,$objACL) # This seems to work
} else { # $objACL is null
write-output "Error developing new permissions object. Leaving folder permissions alone."
}
}
} else {
write-debug ($folder + ": Permissions OK")
}
}
}
check-permissions "c:\temp\test\a"
答案 0 :(得分:2)
"适用于"值由InheritanceFlags
和PropagationFlags
的组合定义(实际上定义了传播的限制方式)。这里概述了哪些值产生哪些"适用于"由于空间有限,设置(ContainerInherit
和ObjectInherit
分别缩写为CI
和OI
:
Apply To Inheritance Propagation
-------- ----------- -----------
This folder only None any
This folder, subfolders and files CI, OI None or NoPropagateInherit
This folder and subfolders CI None or NoPropagateInherit
This folder and files OI None or NoPropagateInherit
Subfolders and files only CI, OI InheritOnly
Subfolders only CI InheritOnly
Files only OI InheritOnly
有关传播规则的更详细说明,请参阅@CB提到的here。在对你的问题的评论中。