Im doing some work with C# and AD and Im missing something right now that I cant seem to see.

I want to get a description of a security group in Active Directory and use that in a tooltip.

I have all the security groups but Im not sure how to get that description.

Here is the code for security groups (and additional non working code for trying to get the description field)

    /* ABOVE THIS THERE IS A LOT MORE CODE BUT THIS IS THE PART THAT LOADS THE GROUPS FROM AD AND ALSO PUTS IT IN A COMBOBOX */
            //Groups:
            // create your domain context
            PrincipalContext ctx = new PrincipalContext(ContextType.Domain, "domain.com");

            // define a "query-by-example" principal - here, we search for a GroupPrincipal 
            GroupPrincipal qbeGroup = new GroupPrincipal(ctx);

            // create your principal searcher passing in the QBE principal    
            PrincipalSearcher srch = new PrincipalSearcher(qbeGroup);

            // find all matches
            foreach (var found in srch.FindAll())
            {
                if (found.DistinguishedName.Contains("OU=DOMAIN,DC=domain,DC=com"))
                {
                    Globals.groups.Add(found.SamAccountName);
                    if (!Globals.groups.Contains("excludedgroup1") && !Globals.groups.Contains("excludedgroup2"))
                    {
                        Globals.tooltipforgroups.Add(found.Description);
                    }

                }
                // do whatever here - "found" is of type "Principal" - it could be user, group, computer.....          
            }

            var array = Globals.groups.Distinct().ToArray();

            foreach (string x in array)
            {
                if (x != "excludedgroup1" && x != "excludedgroup2")
                {
                    comboBoxDepart.Items.Add(x);

                }

            }

Im obviously missing something very obvious.

Recommended Answers

All 3 Replies

I took a look into this and came away a little worn. That is, I didn't find any specific example where this is. So if I had to do this I'd find out if any of the command line tools report this. Then I can research how it did that.

Helps 0 with modifying the code I have

I have a few books on the subject but none revealed more than what I found with googles. Sorry you haven't found an answer yet.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.