PowerShell Active Directory列出所有多值属性

时间:2018-03-06 10:21:12

标签: powershell active-directory

不确定我是否在这里追逐野鹅但是根据主题,我需要获得一个AD属性列表,对于用户ObjectClass,它是多值的。

例如,proxyAddresses交换特定属性是多值的,其中extensionAttribute *仅接受单个字符串。

我们使用了一个高度自定义的架构,虽然我可以浏览每个属性文档,但我宁愿通过PowerShell获取上述属性的列表。

我尝试过使用ldp.exe但无法获得所需的结果,并且想知道是否有办法通过PowerShell或.Net托管代码执行此操作。

提前感谢任何帮助/指针。

1 个答案:

答案 0 :(得分:1)

因此,您必须查询目录的Schema部分并查找 objectClass attributeSchema attribute isSingleValued(FALSE)。区别名称wichh的部分是不变的:CN=Schema,CN=Configuration

首先尝试使用CSV:

csvde -f MultivaluedAttributes.csv -d CN=Schema,CN=Configuration,DC=MySubdomain,DC=MyDomain,DC=com -r "(&(objectclass=attributeSchema)(isSingleValued=FALSE))" -l lDAPDisplayName

这是powershell代码。

# LDAPSchemaQuery.PS1
try
{
  $dn = New-Object System.DirectoryServices.DirectoryEntry ("LDAP://179.22.21.01/CN=Schema,CN=Configuration,DC=MyDomain,DC=MyExt","MyUser", 'MyPassword')
  # Query into the Schema
  # csvde -f MultivaluedAttributes.csv -d CN=Schema,CN=Configuration,DC=office,DC=coyotesystems,DC=com -r "(&(objectclass=attributeSchema)(isSingleValued=FALSE))" -l lDAPDisplayName
  $Rech = new-object System.DirectoryServices.DirectorySearcher($dn)
  #$Rech.filter = "(&(objectclass=user)(mail=*)(!(UserAccountControl:1.2.840.113556.1.4.803:=2)))"
  $Rech.filter = "(&(objectclass=attributeSchema)(isSingleValued=FALSE))"
  $Rech.SearchScope = "subtree"
  $dumy=$Rech.PropertiesToLoad.Add("lDAPDisplayName")

  $adAttributes = $Rech.findall()
  foreach ($adAttribute in $adAttributes) 
  {
    $multivaluedAttribute =  try{$adAttribute.Properties["lDAPDisplayName"]}catch{""}
    $multivaluedAttribute
  }
}
catch
{
  Write-Verbose "LDAPSchemaQuery : PB with $($adAttribute.Path)"
}
相关问题