0

For the past few days i have been trying to get specific properties (Name, Title, etc.) from an ADSI search of someones direct reports with no luck. Here is my current code:

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

So far, i have tried

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

This returns nothing of course since was just trying to grab a name, so i am not sure how to narrow it down, any help would be appreciated. Thanks!

Travis M
  • 105
  • 1
  • 2
  • 14

2 Answers2

2

This

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

is not going to work, since directreports is a collection of DN entries.

Put it in a loop instead:

foreach($DirectReportDN in $searcher.FindAll().Properties.directreports){
    $DirectReport = [adsi]"LDAP://$DirectReportDN"
    # Now do $DirectReport.Properties.Name etc.
}
Mathias R. Jessen
  • 157,619
  • 12
  • 148
  • 206
0

Is this what you're looking for ?

Get-ADUser -Identity $user -Properties DirectReports | Select-Object -ExpandProperty DirectReports
Ramil
  • 87
  • 1
  • 11