• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 382
  • Last Modified:

Query Active Directory groups and add individuals to datagrid

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
kdeutsch
Asked:
kdeutsch
  • 3
  • 2
  • 2
1 Solution
 
sujeshvaCommented:
You want to lookup users from a given AD group?
0
 
kdeutschAuthor Commented:
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
 
sujeshvaCommented:
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
Free Tool: IP Lookup

Get more info about an IP address or domain name, such as organization, abuse contacts and geolocation.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

 
kdeutschAuthor Commented:
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
 
kdeutschAuthor Commented:
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
 
nmarunCommented:
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
 
nmarunCommented:
Please don't delete this issue. It has some valuable information from experts that others may find useful.
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

Join & Write a Comment

Featured Post

Free Tool: SSL Checker

Scans your site and returns information about your SSL implementation and certificate. Helpful for debugging and validating your SSL configuration.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

  • 3
  • 2
  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now