如何使用PowerShell查找Active Directory类的“ Schema-Id-Guid”和属性的“ System-Id-Guid”

时间:2018-12-28 21:23:25

标签: .net powershell ldap

我需要创建一些新的访问控制项(ACE),以使用PowerShell委派给特定的Active Directory OU。

这些规则需要授予/拒绝对“计算机”对象上的“ NT AUTHORITY \ SELF”用户帐户的特定属性的访问。

我正在使用System.DirectoryServices.ActiveDirectoryAccessRule .NET类创建ACE。 The constructor that I require to create this object需要具有所需属性和类的GUID。

现在我可以使用下面编写的PowerShell代码来创建此规则了

# Get the security descriptor for the desired OU
$ouPath = "AD:\\OU=TestOU,DC=example,DC=com"
$acl = Get-Acl $ouPath

# Get the SID of the "NT AUTHORITY\SELF" user account
$account = [System.Security.Principal.NTAccount]::New("NT AUTHORITY", "SELF")
$accountSID = $account.Translate([System.Security.Principal.SecurityIdentifier])

# Property values for ActiveDirectoryAccessRule
$identity = [System.Security.Principal.IdentityReference]$accountSID
$adRights = [System.DirectoryServices.ActiveDirectoryRights]("ReadProperty, WriteProperty")
$type = [System.Security.AccessControl.AccessControlType]("Allow")
$objectType = [System.Guid]::New("bf9679d9-0de6-11d0-a285-00aa003049e2")
$inheritanceType = [System.DirectoryServices.ActiveDirectorySecurityInheritance]("Descendents")
$inheritedObjectType = [System.Guid]::New("bf967a86-0de6-11d0-a285-00aa003049e2")

# Create the new rule object
$ace = [System.DirectoryServices.ActiveDirectoryAccessRule]::New($identity, $adRights, $type, $objectType, $inheritanceType, $inheritedObjectType)

# Add the rule to the ACL
$acl.AddAccessRule($ace)

# Change the security descriptor
Set-Acl -AclObject $acl $ouPath

上面的代码示例允许对Computer类的Network-Address属性进行读写。引用的GUID如下:

Network-Address: System-Id-Guid bf9679d9-0de6-11d0-a285-00aa003049e2

Computer: Schema-Id-Guid bf967a86-0de6-11d0-a285-00aa003049e2

我唯一的问题是我必须手动查找所需属性和类的GUID。

所以我的问题是:

有人知道仅使用CN或Ldap-Display-Name查找这些GUID的方法吗?

1 个答案:

答案 0 :(得分:0)

Theo提供了指向答案的链接。

Get Property guid

我将复制/粘贴Mathias R. Jessen的答案:

您可以从架构中检索属性的GUID:

  1. 查询schemaNamingContext中的attributeSchema对象
  2. 在ldapDisplayName上过滤,GUI显示的属性名称
  3. 获取schemaIDGUID属性值并在ACE中使用它

为了简单起见,我将使用RSAT ActiveDirectory模块,但是您可以对任何ldap客户端执行此操作:

$attrSchemaParams = @{
    SearchBase = (Get-ADRootDSE).schemaNamingContext
    Filter = "ldapDisplayName -eq 'pwmEventLog' -and objectClass -eq 'attributeSchema'"
    Properties = 'schemaIDGUID'
}
$pwmEventLogSchema = Get-ADObject @attrSchemaParams

$pwmEventLogGUID = $pwmEventLogSchema.schemaIDGuid -as [guid]
相关问题