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.