在过去的几天里,我一直试图从某人的直接报告的ADSI搜索中获取特定的属性(名称,标题等(,但没有运气。这是我当前的代码:
$searcher = [adsisearcher]"(samaccountname=$user)"
$DirectReports = $searcher.FindAll().Properties.directreports
到目前为止,我已经尝试过
$searcher = [adsisearcher]"(samaccountname=$user)"
$dr = [adsi]('LDAP://' + $searcher.FindAll().Properties.directreports)
$drfinal = $dr.name
这当然不会返回任何内容,因为只是想抓住一个名字,所以我不确定如何缩小范围,任何帮助将不胜感激。谢谢!
$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.
}
这是你要找的吗?
Get-ADUser -Identity $user -Properties DirectReports | Select-Object -ExpandProperty DirectReports