【问题标题】:Is there a complete list of Active Directory attributes, and a mapping to LDAP?是否有完整的 Active Directory 属性列表以及到 LDAP 的映射?
【发布时间】:2017-01-03 15:55:34
【问题描述】:

我正在使用 LDAP 接口(使用 iads.h)从 c++ 查询 Active Directory。 我注意到用户的属性名称有所不同。

在 Powershell 中执行时

 Get-ADUser sih -Properties *

有一个属性EmailAddress。从 C++ 查询 AD 时,找不到属性 EmailAddress。但是,可以使用 Powershell 和 C++ 找到邮件。

是否有任何映射,或者为什么某些属性存在于 Powershell 中,而不存在于 User 对象的 C++ 接口中?

注意:使用 Active Directory Explorer (https://technet.microsoft.com/en-us/sysinternals/adexplorer.aspx) 时,也不会为用户显示属性 EmailAddress。看来这里显示的所有属性都可以从 C++ 中获取。

我正在寻找从 AD 到 LDAP 的映射,以提供从 AD 获取所有值的可能性。

【问题讨论】:

    标签: c++ powershell active-directory ldap


    【解决方案1】:

    这是两个不同的问题。

    对于内部属性名称和 LDAP 显示名称之间的映射: 它被称为 Schema :-)

    检索所有带有objectClass=attributeSchema 的对象并比较adminDisplayNamelDAPDisplayName 的属性值:

    Get-ADObject -Filter 'objectClass -eq "attributeSchema"' -SearchBase 'CN=Schema,CN=Configuration,DC=forest,DC=tld' -Properties adminDisplayName,lDAPDisplayName |Select-Object adminDisplayName,lDAPDisplayName
    

    对于 PowerShell ActiveDirectory 模块中用户友好的属性名称(如 EmailAddress)和 LDAP 显示名称(如 mail)之间的映射,这些在 Microsoft.ActiveDirectory.Management.dll 程序集中被硬编码为内部常量.

    以下是使用反射魔法检索它们的方法:

    # Import the Active Directory module:
    Import-Module ActiveDirectory
    
    # Now, obtain a reference to the assembly itself:
    $ADAssembly = [Microsoft.ActiveDirectory.Management.ADEntity].Assembly
    
    # Now we'll need to retrieve the internal class that defines the constants:
    $LDAPAttributes = $ADAssembly.GetType('Microsoft.ActiveDirectory.Management.Commands.LdapAttributes')
    
    # Then use GetFields() to retrieve the internal constants
    $LDAPNameConstants = $LDAPAttributes.GetFields('Static,NonPublic') |Where-Object {$_.IsLiteral}
    
    # Finally build a hashtable with the Property Names -> LDAP Name mapping
    $LDAPPropertyMap = @{}
    $LDAPNameConstants |ForEach-Object {
        $LDAPPropertyMap[$_.Name] = $_.GetRawConstantValue()
    }
    

    $LDAPPropertyMap 现在包含您的映射

    【讨论】:

      【解决方案2】:

      PowerShell AD cmdlet 不仅仅返回用户的基本属性。为了使帐户信息更易于使用,他们创建了额外的属性,其中一些只是具有更“会说话”的名称(例如mailEmailAddress),其他则将原始数据转换为更易于理解的格式(例如pwdLastSet→@ 987654325@, accountExpiresAccountExpirationDate) 或显示特定标志(例如Enabled,它指示标志ACCOUNTDISABLE 是否设置在userAccountControl 属性中)。

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多