User's memberOf group

Mar 9, 2010 at 9:40 AM

Is there a way to get only the name of the group a user is a member of?

Currently the [DirectoryAttribute("memberOf")] Groups returns something like:

 - CN=ITDept_General, OU=Groups, DC=companyname, DC=com

 - CN=ITDept_Hardware, OU=Groups, DC=companyname, DC=com

I would like just to be able to have a list with ITDept_General, ITDept_Hardware

Jun 10, 2010 at 4:14 AM

That would be when you print from linq, you can define the property of that object. 

Something like this:

  var res = from usr in users
              where usr.FirstName.StartsWith("B") && usr.Office == "2525"
              select new { Name = usr.FirstName + " " + usr.LastName, usr.Office, usr.LogonCount };

    foreach (var u in res)
    {
        Console.WriteLine(u.Name);
    }

 

Jul 8, 2010 at 3:45 PM
sevententh, The memberOf attribute in AD for users only stores the group's distinguished name from what I understand. You would either have to parse that string or do a second look up on the group based on the distinguished name. This also applies to group's members attribute. See http://www.rlmueller.net/MemberOf.htm for more info.