Solved

PHP: Get all groups from Active Directory

Posted on 2013-06-26
3
353 Views
Last Modified: 2013-07-03
I am trying to just get all the global and local groups from active directory.
I am able to bind to the ldap, but I don't know how to go about getting the groups.
Can someone help?

The following code worked with set variables:

$ldapconn = ldap_connect($ad_host,$ad_port) or die("Could not connect to LDAP server.");	
@ldap_set_option($ldapconn , LDAP_OPT_PROTOCOL_VERSION, 3);
@ldap_set_option($ldapconn , LDAP_OPT_REFERRALS, 0);

// binding to ldap server
$ldapbind = ldap_bind($ldapconn,$userlogin, $password);

Open in new window


This is where I don't know what filter to use to get the group:

if ($ldapbind)
{
  $baseDN = "dc=test,dc=local";
  $strFilter = "(ou=accounts)";
  $strAttributes = array("Group");

  $group_search = ldap_search($ldapconn,$baseDN,$strFilter,$strAttributes);
}

Open in new window

0
Comment
Question by:lgduong
  • 2
3 Comments
 
LVL 54

Expert Comment

by:Julian Hansen
ID: 39280482
Try filter objectcategory=group
0
 

Author Comment

by:lgduong
ID: 39281849
JulianH,

It is not objectcategory=group.  It is objectClass=group.  I was able to parse out the group from this.  As a follow up, do you know how I can get the name or number of users that belong to this group?

Thanks for your assistance.
0
 
LVL 54

Accepted Solution

by:
Julian Hansen earned 350 total points
ID: 39282162
You have to get all users in the group and then loop through the collection and count them.

Not a PHP example but illustrates the point

http://blogs.technet.com/b/heyscriptingguy/archive/2007/09/19/how-can-i-count-the-number-of-users-in-a-group.aspx
0

Featured Post

Netscaler Common Configuration How To guides

If you use NetScaler you will want to see these guides. The NetScaler How To Guides show administrators how to get NetScaler up and configured by providing instructions for common scenarios and some not so common ones.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

In this article, we will see the basic design consideration while designing a Multi-tenant web application in a simple manner. Though, many frameworks are available in the market to develop a multi - tenant application, but do they provide data, cod…
This script can help you clean up your user profile database by comparing profiles to Active Directory users in a particular OU, and removing the profiles that don't match.
Learn how to match and substitute tagged data using PHP regular expressions. Demonstrated on Windows 7, but also applies to other operating systems. Demonstrated technique applies to PHP (all versions) and Firefox, but very similar techniques will w…
The viewer will learn how to create a basic form using some HTML5 and PHP for later processing. Set up your basic HTML file. Open your form tag and set the method and action attributes.: (CODE) Set up your first few inputs one for the name and …

777 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question