ADSI returning groups in Global scope and Domain local scope instead of Universal scope

  • Thread starter Thread starter Maziar Aflatoun
  • Start date Start date
M

Maziar Aflatoun

Hi everyone,

I'm having a problem with reading user groups on Active Directory using C#.
It returns all the groups in the Universal scope for a specific user.
However, I only need the groups in Global scope and Domain local scope. Does
anyone know I can modify the following code to this?

DirectoryEntry entry = new DirectoryEntry("LDAP://" + Domain, CurrentUser,
pwd, AuthenticationTypes.Secure);
DirectorySearcher mySearcher = new DirectorySearcher(entry);


// Change this search for anything
mySearcher.Filter = ("(sAMAccountName="+CurrentUser+")");
try
{
System.DirectoryServices.SearchResult resEnt = mySearcher.FindOne();

// Display all groups for this user
object obGroups = de.Invoke("Groups");
foreach (object ob in (IEnumerable)obGroups)
{
DirectoryEntry obGpEntry = new DirectoryEntry(ob);
group = obGpEntry.Name.Replace("CN=", "");
Response.Write("Group: " + group + "<br>");
}
....


Thank you
Maz A.
 
You need to refine your filter and include Grouptype filtering (search MSDN
platform sdk for ADS_GROUP_TYPE_ENUM and DirectorySearcher samples ).
Following is a small sample:

"....(&(sAmAccount...)(objectCategory=group)(groupType:1.2.840.113556.1.4.804:=4)"
// Domain local groups only (4)

Willy.
 
Back
Top