Ok just to be sure :-)
Use a directorySearcher with a filter...
ntDirectoryGroups = new DirectoryEntry(bindNTDomainPath,bindNTUser,
bindNTPassword);
src = new DirectorySearcher();
// specify properties to load
string[] props = {"cn", more properties};
src.PropertiesToLoad.AddRange(props);
src.SearchRoot = ntDirectoryGroups;
src.SearchScope = SearchScope.Subtree;
// return all groups except "domain computers" and "domain controllers" and
.......
src.Filter = "(&(objectCategory=group)(!cn=domain computers)(!cn=domain
controllers))";
SearchResultCollection res = src.FindAll();
// process the objects in the collection
foreach(SearchResult sc in res) {
.....
Willy.
"Prasad Karunakaran" <pr*******@hotmail.com> wrote in message
news:87**************************@posting.google.c om...
Willy,
It is an Active Directory domain. Thanks for your help.
regards,
Prasad
"Willy Denoyette [MVP]" <wi*************@pandora.be> wrote in message
news:<uh*************@TK2MSFTNGP10.phx.gbl>... Please specify what domain NT or AD.
Willy.
"Prasad Karunakaran" <pr*******@hotmail.com> wrote in message
news:87**************************@posting.google.c om... >I have the following C# code to enumerate the list of groups in a
> domain using ADSI. The problem is if the domain contains machine
> accounts ($) it get those accounts too.
>
> Can somebody help me here to filter out the machine accounts so that I
> get only the NT group objects.
>
> public ArrayList GetNTGroups()
> {
> DirectoryEntry ntDirectoryGroups = null;
> try
> {
> ntDirectoryGroups = new DirectoryEntry(bindNTDomainPath,
> bindNTUser, bindNTPassword);
> ArrayList groupsArray = new ArrayList();
> foreach(DirectoryEntry group in ntDirectoryGroups.Children)
> {
> switch(group.SchemaClassName.ToLower())
> {
> case "group" :
> groupsArray.Add(group.Name);
> break;
> default :
> break;
> }
> }
> groupsArray.Sort();
> return groupsArray;
> }
> catch(COMException ex)
> {
> return null;
> }
> finally
> {
> ntDirectoryGroups.Dispose();
> }
> }
>
> Thanks,
>
> Prasad