All Accounts

This script will display all user accounts in AD, including service accounts. In my AD we have a field called EmployeeType, which we set to Service for service accounts .

The important part to note is the ldap query.


Code Snip

$ds = ldap_connect("");
$OU = "OU=My Company,DC=global,DC=domain,DC=com";

$OUQuery = "(&(objectCategory=Person)(objectClass=User)(!(employeetype=*ervice)))"; 

if ($ds)
    $r = ldap_bind($ds, "domain\eldap", "password");    

		$sr   = ldap_search($ds, $OU, $OUQuery);
		$info = ldap_get_entries($ds, $sr);		

		for ($i=0; $i<$info["count"]; $i++)
            for ($x=0; $x<$info[$i]["count"]; $x++)
               echo "<B>".$info[$i][$x].":</b> ". $info[$i][$info[$i][$x]][0]."<br>";
			 echo "<HR>\n";


Leave a Reply