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.
(&(objectCategory=Person)(objectClass=User)(!(employeetype=*ervice)))
Code Snip
<?php
$ds = ldap_connect("server-dc.global.domain.com");
$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");
if($r)
{
$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";
}
}
ldap_close($ds);
}
?>