Often when developing intranets, we need to retrieve user accounts from Active Directory (for example, verifying security access, getting a list of employees at a specific office, or simply finding out who just joined).
For any good developer, repeating codes should be avoided where possible, so a simple function was created to deal with querying against Active Directory.
Code snippet to query Active Directory
Code snippet to use the function
The idea is to only keep things that are essential in the common function. Anything else should be defined by the invoking function (such as setting the search filter or fields to retrieve). This simple approach should provide a nice balance between efficiency and flexibility.