SET-ACL через powershell для объекта компьютера - PullRequest
0 голосов
/ 01 октября 2018

Я пытаюсь изменить разрешение для нескольких компьютеров в моем домене, чтобы им было разрешено аутентифицировать междоменный домен.

Мой код прост, однако я получаю сообщение об ошибке.

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: Этот идентификатор безопасности не может быть назначен как владелец этого объектаВ строке: 88 символов: 5 + Set-Acl -AclObject $ ComputerACL -Path $ computersADPath + ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + CategoryInfo: NotSpecified: (CN = testComputer, OU = Co ... C = поддомен, DC = домен: строка: строка)[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

Любая помощь будет принята с благодарностью.Спасибо.

1 Ответ

0 голосов
/ 02 октября 2018

Для всех, кто столкнулся с этой проблемой, вот решение:

В принципе, как работают 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

...