【问题标题】:Ldap filter for multiple Ou's Powershell用于多个欧的 Powershell 的 Ldap 过滤器
【发布时间】:2019-10-25 11:36:14
【问题描述】:

大家好,大家对 Powershell 还是很陌生,之前从未使用过 Ldap -filter,所以我有一个问题。是否可以使用一个 Ldap 过滤器从多个 Ou 中获取 AD-User?

OU=D5,OU=Standard,OU=User,OU=1,DC=test,DC=for-me,DC=nl
OU=D3,OU=Standard,OU=User,OU=1,DC=test,DC=for-me,DC=nl
OU=G2,OU=General,OU=User,OU=1,DC=test,DC=for-me,DC=nl
OU=C6,OU=Expired,OU=User,OU=1,DC=test,DC=for-me,DC=nl

对不起,我什至没有代码示例,但我尝试过的任何东西都没有接近我想要的。 我愿意接受小费、提示、想法等。已经谢谢了。

【问题讨论】:

  • 1.为什么需要将它放在一个过滤器中? 2. 您可以随时使用foreach 循环来完成您的操作。 3. 是的,也有可能。您可以将过滤器语句与布尔运算符结合使用。示例 Get-ADUser -Filter { Email -like "*" -and Surname -eq "smith" }-or-Get-ADUser -Filter { Email -like "*" -and sn -eq "smith" } LDAP 过滤器等效项:(&(sn=smith)(objectClass=user)(email=*))

标签: powershell filter ldap ou


【解决方案1】:

您不能使 OU 成为 LDAP 过滤器的一部分。但您可以将 OU 作为搜索的基础并发出多个搜索。

# an array of OUs, this could also be achieved with e.g. $OUs = Get-Content 'some_file.txt'
$OUs = @(
    "OU=D5,OU=Standard,OU=User,OU=1,DC=test,DC=for-me,DC=nl"
    "OU=D3,OU=Standard,OU=User,OU=1,DC=test,DC=for-me,DC=nl"
    "OU=G2,OU=General,OU=User,OU=1,DC=test,DC=for-me,DC=nl"
    "OU=C6,OU=Expired,OU=User,OU=1,DC=test,DC=for-me,DC=nl"
)

foreach ($ou in $OUs) {
    Get-ADUser -SearchBase $ou
}

【讨论】:

  • 嗯,它必须是一个 ldap 过滤器,结果必须在一个字符串中,因为我不能使用正常的循环。
  • 它不能是 LDAP 过滤器,因为 OU 不能是 LDAP 过滤器的一部分。另外,我不确定您所说的 “结果必须在一个字符串中” 是什么意思。结果很少是 PowerShell 中的字符串,在这种情况下,结果是 ADUser 对象。
【解决方案2】:

嗯,它不是 LDAP 查询,在非常大的环境中可能是可疑的,但通常我建议使用 Powershell 的过滤器选项,如下所示:

Get-ADUser -Filter  * | Where-Object { $_.DistinguishedName.split(",",2)[1] -in 
    "OU=D5,OU=Standard,OU=User,OU=1,DC=test,DC=for-me,DC=nl",
    "OU=D3,OU=Standard,OU=User,OU=1,DC=test,DC=for-me,DC=nl",
    "OU=G2,OU=General,OU=User,OU=1,DC=test,DC=for-me,DC=nl",
    "OU=C6,OU=Expired,OU=User,OU=1,DC=test,DC=for-me,DC=nl"
}

【讨论】:

  • 小心 - CN=Doe\, John,OU=D5,OU=Standard,OU=User,OU=1,DC=test,DC=for-me,DC=nl 是一个有效的 DN
  • 嗯,它必须是一个 ldap 过滤器,结果必须在一个字符串中,因为我不能使用正常的循环。
猜你喜欢
  • 1970-01-01
  • 2019-02-06
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2018-09-27
  • 2012-11-30
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多