473,413 Members | 1,705 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,413 software developers and data experts.

ADSI Query to filter out machine accounts in the domain

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
Nov 15 '05 #1
3 3996
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

Nov 15 '05 #2
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

Nov 15 '05 #3
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

Nov 15 '05 #4

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

2
by: Christopher Johannsen | last post by:
Good Day: I am working on building a tool Using ASP/COM & IIS5.1 for a non-administrative technical support team to change domain passwords for users. I have the basic interface built and...
14
by: Arran Pearce | last post by:
Hi, I am looking for a way to use System.DirectoryServices to find all users on a domain whos accounts are either locked out or disabled. I have used ADSIEdit and the mmc schema add-in to try...
2
by: YRao | last post by:
I am going to create intranet application using Windows Authentication using C# asp.net I am having following problem: 1 setting windows Authentication, it will validate for all users, user...
3
by: Roy Osherove | last post by:
Hi folks. I have an ASP.Net application that runs a .Net dll that uses WMI and ADSI(both managed) to connect to a given IIS root and search through it. When not using the ASP.Net client, but...
5
by: Tim::.. | last post by:
Hi can someone please tell me how I change this directory service query so that it searches through each record in the active directory and returns all the accounts! At the moment I can only get...
14
by: Jonathan Smith | last post by:
I am trying to develop an app using ADSI. I have the following code: Dim ADSUser As IADsUser ADSUser = GetObject("LDAP://CN=jonsmith,CN=users,DC=domain,DC=com") ...
1
by: LittlePython | last post by:
I am a little confused on why I can not detect an object that does not exist with a try and except. If I understand ADSI correctly from what I have read you do not create these objects but rather...
4
by: shashank kadge | last post by:
hi all, i am trying to get local admin users and groups on a windows server. here is the C# code that i am using...
8
by: John | last post by:
Hi, gurus, How can I implement the following feature in C#: Set objGroup = GetObject("WinNT://" & strComputer & "/" & strGroup & ", group") For Each objMember In objGroup.Members...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...
0
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.