Click here to Skip to main content
15,888,170 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
Hello,
I new to above concept.I want all domain users name ,Please give me idea or solution

What I have tried:

I have Active directory's openQuery concept like****'****'****'****'****'****'
GO 
EXEC master.dbo.sp_addlinkedserver @server = N'ADSI_12', @srvproduct=N'Active Directory Service Interfaces', @provider=N'ADSDSOObject', @datasrc=N'adsdatasource'
EXEC master.dbo.sp_addlinkedsrvlogin @rmtsrvname=N'ADSI_12',@useself=N'False',@locallogin=NULL,@rmtuser=N'JKMARLOCAL\SUJATA.SHINDE',@rmtpassword='*********'




and select command like

SELECT * FROM OpenQuery ( 

  ADSI_12,  
  'SELECT displayName, telephoneNumber, mail, mobile, facsimileTelephoneNumber 
  FROM  ''LDAP://JKUMARLOCAL.com,DC=JKUMARLOCAL,DC=com'' 
  WHERE objectClass =  ''SUJATA.SHINDE'' 
  ') AS tblADSI
order BY displayname


but i does not meet my requirment
Posted
Updated 21-Feb-17 23:40pm
Comments
Patrice T 22-Feb-17 3:37am    
"but i does not meet my requirment"
We just have to guess what are your requirements.
SujataJK 22-Feb-17 4:43am    
i got solution...
Great. Please add a solution.
SujataJK 22-Feb-17 5:35am    
PrincipalContext ctx = new PrincipalContext(ContextType.Domain);

// define a "query-by-example" principal - here, we search for all users
UserPrincipal qbeUser = new UserPrincipal(ctx);

// create your principal searcher passing in the QBE principal
PrincipalSearcher srch = new PrincipalSearcher(qbeUser);

// find all matches
foreach (var found in srch.FindAll())
{
//Label1.Text = found.Name;
// do whatever here - "found" is of type "Principal" - it could be user, group, computer.....
DropDownList1.Items.Add(found.Name);
DropDownList2.Items.Add(found.UserPrincipalName);
}

1 solution

Adding answer on behalf of OP.
PrincipalContext ctx = new PrincipalContext(ContextType.Domain);

// define a "query-by-example" principal - here, we search for all users
UserPrincipal qbeUser = new UserPrincipal(ctx);

// create your principal searcher passing in the QBE principal 
PrincipalSearcher srch = new PrincipalSearcher(qbeUser);

// find all matches
foreach (var found in srch.FindAll())
{
    //Label1.Text = found.Name;
    // do whatever here - "found" is of type "Principal" - it could be user, group, computer..... 
    DropDownList1.Items.Add(found.Name);
    DropDownList2.Items.Add(found.UserPrincipalName);
}
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900