【问题标题】:PowerShell Active Directory list all Multi-Valued attributesPowerShell Active Directory 列出所有多值属性
【发布时间】:2018-03-06 10:21:11
【问题描述】:

不确定我是否在这里链接了野鹅,但根据主题,我需要为用户 ObjectClass 获取具有多重价值的 AD 属性列表。

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

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

我已经尝试使用 ldp.exe,但无法获得预期的结果,我想知道是否有办法通过 PowerShell 或 .Net 托管代码来实现。

在此先感谢您的帮助/指点。

【问题讨论】:

  • 好吧,显然我的问题不清楚,因为我们在谈论两个不同的事情,或者我无法弄清楚你的例子与我原来的问题有何关系。不要误会我的意思,我非常感谢您的帮助,但这不是我想要的

标签: powershell active-directory


【解决方案1】:

因此您必须查询目录的架构部分并查找 objectClass attributeSchemaattribute isSingleValued (FALSE)。 distinguichName 中不变的部分是: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)"
}

【讨论】:

  • 谢谢,但也许我的问题不清楚,我试图报告在架构级别定义为多值的所有属性,而不是报告现有属性和/或其值。
  • 所以,同一个玩家再次射击...我尝试纠正 PowerShell 代码。
  • 唉,无论如何它都没有返回任何值,因为它可以通过 GUI 应用程序构建 ldapfilter,但仍然没有骰子。好消息是,与此同时,我找到了一个可以满足我需求的属性,但我将继续追求这一点,因为我认为有一种简单的方法来获取此类信息会很方便
  • 这两种方法对我来说都很好,请注意尊重 DN 路径,您可以使用 Apache Directory Studio 来验证这一点。
  • 哦,感谢 Apache Directory Studio 的提示,我不知道该工具......我很傻,我最终编写了一个适合我需要的工具(现在我真的觉得很傻)。根据 DN.... 我在我的实验室 DC 中使用我的生产域之一,所以很傻 x 2 :) 像我一样工作,我需要过滤掉用户唯一的属性,但这就是说的部分,非常感谢!
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 2015-11-29
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2023-03-26
  • 2014-07-17
相关资源
最近更新 更多