Class: EasyADSI
OS Requirements: Windows XP, Vista, 2000, 2003

Purpose

EasyADSI was created out of necessity when interacting with Microsoft's Active Directory(AD). The built in functionality of PHP's LDAP Function is great when interfacing with other LDAP servers but is lacking when interfacing with AD. This was specifically problematic when trying to modify/add entries within AD.

Requirements

EasyADSI uses the COM functionality built into PHP therefore it can only be run on Windows Operating Systems.

EasyADSI In Action

Getting Started
Search Entire Directory: $test = new EasyADSI("AD_USER","AD_PASS","AD_DOMAIN");
- This will allow you to search the entire domain including all containers & OUs
Search Non-Recursive: $test = new EasyADSI("AD_USER","AD_PASS","AD_DOMAIN",1);
- This will allow you to search only the container or OU you have specified

Selecting a Domain Controller
Setting your Domain Controller (DC): $test->useDC("ad.server.com");
- The function will automatically parse the domain name into the correct LDAP format
Setting your DC and Container/OU: $test->useDC("ad.server.com","CN=Users,DC=ad,DC=server,DC=com");
- You can also specify which container or OU you would like to use

Setting the Selection
SQL type query for AD: $test->setSelection("distinguishedName,sAMAccountName");
- This is simular to selecting your fields in any SQL statement (LDAP cannot use the "*" wildcard)
AD query using XML: $test->setSelection("user",true);
- Using the XML file function will allow you to get basic fields in AD

WHERE, ObjectClass & ObjectCategory
SQL Where style queries:
$test->setWhere("sAMAccountName = 'USER_ID'");
$test->objectClass("user");
$test->objectCategory("person");
- Technically these are not manditory fields but they help in pearing down your query

Sort
Sorting your query: $test->setSort("sAMAccountName");
- Pretty self explanitory but note that ADSI can only sort asscending

Putting the Query All Together
Finallizing the object: $test->select();
- This function thows everything together

Query into an Array
$final = $test->recordSet();
- This takes the complete recordset and sticks it into a multidimentional array that PHP can use


Miscellaneous Functions
I added a few functions that are ADSI speciffic because of some of the strange ways the fields output them.
$test->resetPassword("CN=User Name,OU=Users,DC=ad,DC=server,DC=com","NewPassword");
$test->passwordExpires("CN=User Name,OU=Users,DC=ad,DC=server,DC=com");
$test->lastLogin("CN=User Name,OU=Users,DC=ad,DC=server,DC=com");
$test->isAccountLocked("CN=User Name,OU=Users,DC=ad,DC=server,DC=com");
- These functions a pretty self explanitory


Future
I will be adding some functionality around actually modifying, adding & removing accounts

Links For more information about ADSI visit MSDN @ http://msdn.microsoft.com/en-us/library/aa772161(VS.85).aspx