无法从 ADSI 直接报告搜索中筛选特定属性

Unable to filter specific properties from ADSI direct reports search

在过去的几天里,我一直在尝试通过 ADSI 搜索某人的直接下属来获取特定属性(姓名、职位等),但没有成功。这是我当前的代码:

$searcher = [adsisearcher]"(samaccountname=$user)"
$DirectReports = $searcher.FindAll().Properties.directreports

到目前为止,我已经试过了

$searcher = [adsisearcher]"(samaccountname=$user)"
$dr  = [adsi]('LDAP://' + $searcher.FindAll().Properties.directreports)
$drfinal = $dr.name

这 returns 当然没什么,因为我只是想抢个名字,所以我不确定如何缩小范围,如有任何帮助,我们将不胜感激。谢谢!

这是您要找的吗?

Get-ADUser -Identity $user -Properties DirectReports | Select-Object -ExpandProperty DirectReports

这个

$dr  = [adsi]('LDAP://' + $searcher.FindAll().Properties.directreports)

不会起作用,因为 directreports 是 DN 条目的集合。

改为将其放入循环中:

foreach($DirectReportDN in $searcher.FindAll().Properties.directreports){
    $DirectReport = [adsi]"LDAP://$DirectReportDN"
    # Now do $DirectReport.Properties.Name etc.
}