set-acl to AD OU

时间:2016-11-16 13:40:54

标签: powershell active-directory

我知道这个主题已经在这里讨论了,但是这里和其他网站上的解决方案似乎对我不起作用。

我想加入CNO:" CLUSTER" OU创建计算机对象的权限。

或多或少所有解决方案都基于以下想法:

$ou = 'OU=sql,OU=prod,DC=ssd,DC=xxx,DC=net'
$cno = 'CLUSTER1'
$sid = [System.Security.Principal.SecurityIdentifier](Get-ADComputer -Filter "name -eq `"$cno`"").SID
$acl = get-acl $ou
$objectGUID = New-Object guid bf967a86-0de6-11d0-a285-00aa003049e2
$guidNull = New-Object guid 00000000-0000-0000-0000-000000000000
$ace1 = new-object System.DirectoryServices.ActiveDirectoryAccessRule $sid,"ReadProperty,GenericExecute","Allow",$guidNull,"None",$guidNull
$acl.AddAccessRule($ace1)
$ace2 = new-object System.DirectoryServices.ActiveDirectoryAccessRule $sid,"CreateChild","Allow",$ObjectGUID,"None",$guidNull
$acl.AddAccessRule($ace2)
set-acl -aclobject $acl $ou

我收到以下错误:

Set-Acl : This security ID may not be assigned as the owner of this object
At line:1 char:8
+ set-acl <<<<  -aclobject $acl $ou
    + CategoryInfo          : NotSpecified: (OU=sql,OU=ssd...=xxx,DC=net:String) [Set-Acl], ADException
    + FullyQualifiedErrorId : ADProvider:SetSecurityDescriptor:ADError,Microsoft.PowerShell.Commands.SetAclCommand

知道什么是错的吗?

2 个答案:

答案 0 :(得分:0)

使用Get-Acl / Set-Acl时,我在文件系统上看到了这个错误。即使您不想要它,Get-Acl也会检索整个ACL。你只想要DACL。 Set-Acl然后尝试编写因Microsoft而失败的整个ACL。尝试将Get-Acl调用更改为:

$acl = (get-acl $ou).Access

这应该只为您提供您尝试附加的访问规则。

修改

对于错误信息的道歉,在文件系统上这是有效的,但AD是&#34;特殊&#34;。潜在的问题是相同的,Get-Acl在尝试设置所有者时会拉出所有内容和Set-Acl chokes。尝试在域管理员的上下文中以管理员身份运行的PowerShell窗口中运行上述命令。这可能会让你强迫它过去。相反,我会尝试使用ADSI加速器。

$ou = 'OU=sql,OU=prod,DC=ssd,DC=xxx,DC=net'
$cno = 'CLUSTER1'
$sid = [System.Security.Principal.SecurityIdentifier](Get-ADComputer -Filter "name -eq `"$cno`"").SID
$ouObject = [ADSI]("LDAP://$OU")
$objectGUID = New-Object guid bf967a86-0de6-11d0-a285-00aa003049e2
$guidNull = New-Object guid 00000000-0000-0000-0000-000000000000
$ace1 = new-object System.DirectoryServices.ActiveDirectoryAccessRule $sid,"ReadProperty,GenericExecute","Allow",$guidNull,"None",$guidNull
$ouObject.psbase.ObjectSecurity.AddAccessRule($ace1)
$ace2 = new-object System.DirectoryServices.ActiveDirectoryAccessRule $sid,"CreateChild","Allow",$ObjectGUID,"None",$guidNull
$ouObject.psbase.ObjectSecurity.AddAccessRule($ace2)
$ouObject.psbase.CommitChanges()

另一个选择是尝试使用dsacls解决它,你需要确切地弄清楚你想要使用哪个permissions syntax。请在运行实时OU之前进行测试。

$ou = 'OU=sql,OU=prod,DC=ssd,DC=xxx,DC=net'
$cno = 'CLUSTER1'
$sid = [System.Security.Principal.SecurityIdentifier](Get-ADComputer -Filter "name -eq `"$cno`"").SID
#should grant the SID Generic Execute, Read Property, Create Children
dsacls $ou /G $sid:GERPCC

答案 1 :(得分:0)

似乎可以在任何AD对象上使用,包括通过DN的DNS记录:

dsacls $DistinguishedName /G "NT AUTHORITY\Authenticated Users:GW"