LDAPSearch

command line ldap search tool.

Testing queries against an active Directory server

ldapsearch -x -LLL -h server.blah.corp -D "kcurran-admin@blah.com" -W -b "OU=People,DC=blah,DC=corp" -s sub "(&(objectCategory=person)(objectClass=user)(sAMAccountName=$USER))" cn mail sn

ldapsearch -x -LLL -h server.blah.corp -D "kcurran-admin@blah.com" -W -b "OU=People,DC=blah,DC=corp" -s sub "(sAMAccountName=$USER)" cn userprincipalname mail sn manager sAMAccountName 

test getting a list of all managers and listing their directReports

ldapsearch -x -LLL -P 3 -h server.blah.corp -D "kcurran-admin@blah.com" -W -b "OU=People,DC=blah,DC=corp" -s sub "(&(objectCategory=person)(objectClass=user)(directReports=*))" cn userprincipalname mail sn manager sAMAccountName directReports > ~/ManagerList.txt 

From windows I would run the following in powershell to get the same data

Get-QADUser -SearchRoot 'blah.corp/People' -LdapFilter "(directReports=*)" | select cn, userprincipalname, mail, sn, manager, sAMAccountName, directReports