我正在尝试创建一个将设置ACL权限的函数,所有数据都来自XML作为字符串,而且我对继承部分没有问题。用这段代码......
$workingPermissions = Get-Acl $target
$acRights = [System.Security.AccessControl.FileSystemRights]$rights
$acInheritanceFlag = [System.Security.AccessControl.InheritanceFlags]::$inheritance
$acPropagationFlag = [System.Security.AccessControl.PropagationFlags]::$propagation
$acType =[System.Security.AccessControl.AccessControlType]::Allow
$acUser = New-Object System.Security.Principal.NTAccount($principal)
$acEntry = New-Object System.Security.AccessControl.FileSystemAccessRule ($acUser, $acRights, $acInheritanceFlag, $acPropagationFlag, $acType)
当只使用一个继承标志时,一切正常,但是当$ inheritance =“ContainerInherit,ObjectInherit”它失败时。 $ rights是以相同的方式构建的,但我的理解是,无论出于何种原因,继承(和传播?)的行为方式不同。 几年前我发现了this thread,我没有看到基于-bor的解决方案允许任何基于字符串的输入。实际上,我根本就不理解它,因为看起来$ is只是被设置为枚举,当然它包含两个枚举,其中设置了$ flag。 无论如何,希望有人可以提供我自己的代码需要,并且也许让我了解链接解决方案中真正发生的事情。
答案 0 :(得分:1)
将Propogation标志保留为None,
尝试这个,它适合我
$SAMAccountName = "SamAccountName" ## Type your User/Group SamAccountName
$Rights = "ReadAndExecute"
$InheritanceFlag = @("ContainerInherit","ObjectInherit")
$PropagationFlag = "None"
$AccessType = "Allow"
$NTAccount = [System.Security.Principal.NTAccount]($SAMAccountName)
$IdentityReference = $NTAccount.Translate([System.Security.Principal.SecurityIdentifier])
$AccessRights = [System.Security.AccessControl.FileSystemRights] $Rights
$InheritanceFlags = [System.Security.AccessControl.InheritanceFlags]$InheritanceFlag
$PropagationFlags = [System.Security.AccessControl.PropagationFlags]$PropagationFlag
$Type = [System.Security.AccessControl.AccessControlType]$AccessType
$AccessRule = New-Object System.Security.AccessControl.FileSystemAccessRule($IdentityReference, $AccessRights, $InheritanceFlags,$PropagationFlags,$Type)
$ACL = Get-Acl $Folder
$ACL.AddAccessRule($AccessRule)
Set-Acl -Path $Folder -AclObject $ACL