?
Solved

Query Active Directory groups and add individuals to datagrid

Posted on 2009-02-12
7
Medium Priority
?
362 Views
Last Modified: 2012-06-27
Never done this before and don't know where to start, I need to query active directory groups and then add the users that are in those groups to a datagrid.  How can I do this.  Can build the datagrid easy but know nothing about querying active directory from asp.net 1.1.  Please help
Thanks
0
Comment
Question by:kdeutsch
  • 3
  • 2
  • 2
7 Comments
 
LVL 3

Expert Comment

by:sujeshva
ID: 23624843
You want to lookup users from a given AD group?
0
 

Author Comment

by:kdeutsch
ID: 23625360
Correct I need to be able to query 8 different active directory groups and pull out these users in a sql query and then put it into asp.net and populate a datagrid.  Once the query is built I can handle rest but don't know syntaxes to query AD.
0
 
LVL 3

Expert Comment

by:sujeshva
ID: 23625382
ok, just for starters, Google System.DirectoryServices. I am in the middle of something and cant write the code to test it. Read it, it has everything you are looking for and probably will have a solution even before I get to it.

-Suj
0
Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 

Accepted Solution

by:
kdeutsch earned 0 total points
ID: 23625535
HI,
Ok here is some code I have copied from net and changed to get working to my situation with help.  How can I take this procedure and create and overall Stored procedure and insert the temp table into permanent table.

create table #MemberOfGroups(
groepNaam varchar(400),
cn varchar(400),
displayName varchar(400))
SET NOCOUNT ON
declare @t varchar(100),@t2 varchar(1000), @ot varchar (4000), @tt varchar (4000);

declare gC cursor
for
select cn, distinguishedName
from openquery
(ADSI,'SELECT cn, distinguishedName
FROM ''LDAP://NGMNA1DCG
WHERE objectCategory = ''group''
and CN = ''NGMN SEC J6 Automation FTS''
or CN = ''NGMN SEC J6 Help Desk (Level 1)''
or CN = ''NGMN SEC J6 Help Desk (Level 2)''
or CN = ''NGMN SEC J4 Admins''
or CN = ''NGMN SEC J8 Admins''
or CN = ''NGMN SEC FMO Admins''
or CN = ''NGMN SEC RRM Admins''
or CN = ''MN Admins''
')
open gC

FETCH NEXT FROM gC INTO @t, @t2
WHILE @@FETCH_STATUS = 0
BEGIN
set @ot = '''SELECT cn, displayName
FROM ''''LDAP://NGMNA1D
WHERE objectCategory = ''''Person'''' AND objectClass = ''''user''''
AND memberOf=''''' + @t2 + '''''';
set @tt = 'select '+ ''''+@t+'''' +' As GroepNaam, cn, displayName from openquery(ADSI,'+ @ot +''') order by cn'

insert into #MemberOfGroups(groepNaam, cn, displayName)
EXEC (@tt)
--print @tt
FETCH NEXT FROM gC INTO @t, @t2
END
CLOSE gC
DEALLOCATE gC

select Distinct(CN), groepNaam as 'Group' from #MemberOfGroups Where lower(substring(CN, 1, 3)) <> 'svc' order by CN
--order by displayName

drop table #MemberOfGroups
0
 

Author Comment

by:kdeutsch
ID: 23625738
Hi,
Ok I found how to insert into permenent table by adding this to the method  I added it right before the Select statement at the bottom, don't know it its correct way to do but it works.  So teh questions i have left are
1.  How can I pull email with this statement as well
2. How can I turn into a sql query statement or a stored procedure that I can run via an asp.net program.

INSERT INTO [IAComplianceDotNet].[dbo].[tblADAccounts]
           ([strName]
           ,[strAccount])
0
 
LVL 27

Expert Comment

by:nmarun
ID: 23629366
Here's another way to do it all in C#.

Read all users:
http://www.codeproject.com/KB/system/everythingInAD.aspx

Add it to the database / query from the database to display it on the grid.
http://www.csharp-station.com/Tutorials/AdoDotNet/Lesson01.aspx


0
 
LVL 27

Expert Comment

by:nmarun
ID: 23681160
Please don't delete this issue. It has some valuable information from experts that others may find useful.
0

Featured Post

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

The article shows the basic steps of integrating an HTML theme template into an ASP.NET MVC project
This post looks at MongoDB and MySQL, and covers high-level MongoDB strengths, weaknesses, features, and uses from the perspective of an SQL user.
Loops Section Overview
With just a little bit of  SQL and VBA, many doors open to cool things like synchronize a list box to display data relevant to other information on a form.  If you have never written code or looked at an SQL statement before, no problem! ...  give i…
Suggested Courses

850 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question