In PHP, how do I do an LDAP query to find all Domain Controllers?
I have no problem getting the members of a user group, such as 'domain admins', by extracting each member[n] from the ldap array. However, the 'domain controllers' does not have member[n] entry for each domain controller.
The following displays the LDAP array without showing any members (If I replace 'domain controllers' with 'domain admins', I see the members):
$group = "Domain Controllers";
$ds = ldap_connect($domain_controller) or die("Couldn't connect to AD!");
ldap_set_option($ds, LDAP_OPT_PROTOCOL_VERSION, 3);
$bd = ldap_bind($ds,$account,$account_pw) or die("Couldn't bind to AD!");
$dn="CN=Users,DC开发者_开发问答=our_domain,DC=com";
$filter="samaccountname=" . $group;
$result=ldap_search($ds, $dn, $filter);
$entries = ldap_get_entries($ds, $result);
echo("<table>");
foreach($entries[0] as $key=>$value){
foreach ($value as $iKey => $iValue) {
echo("<tr><td style='white-space:nowrap;'>\$entries[0][" . $key . "][" . $iKey . "]</td><td>" . $iValue . "</td></tr>");
}
}
echo("</table>");
The Domain Controllers
OU isn't in the Users
OU (unless you've reorganized your AD setup). You need to modify your LDAP query to use a base DN of just DC=our_domain,DC=com
.
精彩评论