【问题标题】:SET-ACL via powershell for computer object通过 powershell 为计算机对象设置 ACL
【发布时间】:2018-10-01 01:45:00
【问题描述】:

我正在尝试修改对我域中多台计算机的权限,以便允许它们跨域进行身份验证。

我的代码很简单,但是我不断收到错误。

Function Add-ADGroupACL
{
    param([string]$Computername,[string]$Access)
    #Get a reference to the RootDSE of the current domain
    $rootdse = Get-ADRootDSE
    #Get a reference to the current domain
    $domain = Get-ADDomain
    #Create a hashtable to store the GUID value of each extended right in the forest
$extendedrightsmap = @{}
Get-ADObject -SearchBase ($rootdse.ConfigurationNamingContext) -LDAPFilter `
"(&(objectclass=controlAccessRight)(rightsguid=*))" -Properties displayName,rightsGuid | 
% {$extendedrightsmap[$_.displayName]=[System.GUID]$_.rightsGuid}

#Create a hashtable to store the GUID value of each schema class and attribute
$guidmap = @{}
Get-ADObject -SearchBase ($rootdse.SchemaNamingContext) -LDAPFilter `
"(schemaidguid=*)" -Properties lDAPDisplayName,schemaIDGUID | 
% {$guidmap[$_.lDAPDisplayName]=[System.GUID]$_.schemaIDGUID}

    #Get the computer  object for modification on
    $Computer = Get-ADComputer -Identity $Computername

    #get the SID of the group you wish to add to the computer.
    $GroupIdentity = New-Object System.Security.Principal.SecurityIdentifier(Get-ADGroup -Identity $Access).SID

    $computersADPath = "AD:\" + $Computer.DistinguishedName
    $ComputerACL = Get-ACL $computersADPath

    #Create a new rule to add to the object
    $newAccessRule = New-Object System.DirectoryServices.ActiveDirectoryAccessRule(
        $GroupIdentity,"ExtendedRight",
        "Allow", 
        $extendedrightsmap["Allowed To Authenticate"],
        "None")

    $newAccessRule
    #Add the rule to the ACL
    $ComputerACL.AddAccessRule($newAccessRule)
    #Set Rules to the ACL
    Set-Acl -AclObject $ComputerACL -Path $computersADPath
}

为了方便起见,我已经发布了整个功能。 简单地这样称呼它

Add-ADGroupACL -Computername 'TestComputer' -Access 'TestGroup'

这是我不断收到的错误消息

Set-Acl : 这个安全 ID 不能被指定为这个对象的所有者 在行:88 字符:5 + 设置 Acl -AclObject $ComputerACL -Path $computersADPath + ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ ~~~~~ + CategoryInfo : NotSpecified: (CN=testComputer,OU=Co...C=subdomain,DC=domain:String) [Set-Acl], ADException + FullyQualifiedErrorId : ADProvider:SetSecurityDescriptor:ADError,Microsoft.PowerShell.Commands.SetAclCommand

访问规则看起来正确。它显示了这一点。

ActiveDirectoryRights : ExtendedRight 
InheritanceType       : None
ObjectType            : 68b1d179-0d15-4d4f-ab71-46152e79a7bc
InheritedObjectType   : 00000000-0000-0000-0000-000000000000
ObjectFlags           : ObjectAceTypePresent 
AccessControlType     : Allow
IdentityReference     : S-1-5-21-2926237862-3770063950-2320700579-361721 
IsInherited       : False 
InheritanceFlags      : None 
PropagationFlags      : None

任何帮助将不胜感激。 谢谢。

【问题讨论】:

    标签: powershell active-directory acl


    【解决方案1】:

    对于遇到此问题的其他人,这里是解决方案。

    基本上,Get-ACL 和 Set-ACL 的工作原理是检索整个 ACL。您对 ACL 进行编辑,然后 Set-ACL 尝试重写整个 ACL。 更多信息:https://docs.microsoft.com/en-us/windows/desktop/secauthz/access-control-entries

    所以基本上您只需要创建一个 ACE 并将其动态添加到 ACL 中。最好使用 DACLS 购买

    代码:

    Function Add-ADGroupACEExtendedRight
    {
        param(
            [string]$Computername = $(throw "Computer name must be specified"),
            [string]$Access = $(throw "User or group in which to give acces must be specifieds"),
            [string]$ExtendedRight = $(throw "Extended Right Property Name Required")
        )
    
        #Get the computer  object for modification on
        $Computer = Get-ADComputer -Identity $Computername
    
        #get the SID of the group you wish to add to the computer.
        $GroupIdentity = New-Object System.Security.Principal.SecurityIdentifier(Get-ADGroup -Identity $Access).SID
    
        #Set Permissions
        dsacls $Computer.DistinguishedName /G $GroupIdentity":CA;"$ExtendedRight
    }
    

    用法:

    Add-ADGroupACEExtendedRight -Computername "TestAsset" -Access "GroupID" -ExtendedRight "Allowed To Authenticate"
    

    您可以在此处添加任何扩展。 更多关于 DACLS 的信息:https://technet.microsoft.com/pt-pt/library/cc787520%28v=ws.10%29.aspx?f=255&MSPPError=-2147217396

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2015-10-01
      • 1970-01-01
      • 2021-09-19
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2014-01-29
      • 1970-01-01
      相关资源
      最近更新 更多