I'm using this code to filter the groups of my active directory domain:
List<Department> result = new List<Department>();
using (PrincipalContext ctx = getContext())
{
GroupPrincipal gp = new GroupPrincipal(ctx);
PrincipalSearcher search = new PrincipalSearcher(gp);
result = (from g in search.FindAll()
where !g.DistinguishedName.Contains("CN=Builtin")
select new Department()
{
name = g.Name,
description = g.Description
}).ToList();
}
return result;
As you can see, I already filter the ones that are included by the system, the builtin ones. But the system has some othes, like the ones created by SQL Server. I need to know if there is a way to show only the ones that were created by the server administrator. Is there a way to do that?
This is my getContext code:
public PrincipalContext getContext()
{
return new PrincipalContext(ContextType.Domain, WebConfigurationManager.AppSettings["SERVER"].ToString(), WebConfigurationManager.AppSettings["DOMAIN"].ToString() + @"\" + WebConfigurationManager.AppSettings["USER"].ToString(), WebConfigurationManager.AppSettings["PASSWORD"].ToString());
}
And the values on the server are these:
<add key="SERVER" value="192.168.1.2"/>
<add key="DOMAIN" value="intra"/>
<add key="USER" value="xxxxx"/>
<add key="PASSWORD" value="xxxxxxx"/>