这是两个不同的问题。
对于内部属性名称和 LDAP 显示名称之间的映射:
它被称为 Schema :-)
检索所有带有objectClass=attributeSchema 的对象并比较adminDisplayName 和lDAPDisplayName 的属性值:
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 现在包含您的映射