?
Solved

writing c# code to get info from LDAP

Posted on 2013-06-13
4
Medium Priority
?
1,185 Views
Last Modified: 2013-10-14
Hi

I wrote an intranet, and now they want to pull the correct phone numbers for employee's from Active directory via LDAP

I've never used LDAP before, and the Networking department are a pain in the butt to work with, they never help and are always block things

What sort of questions do I need to be asking, or areas to be looking into before starting?
Any advice appreciated to get me upto speed

Thanks
0
Comment
Question by:websss
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
4 Comments
 
LVL 10

Accepted Solution

by:
Monica P earned 2000 total points
ID: 39243923
Hi
Refer this link:
http://www.wisesoft.co.uk/scripts/vbscript_extract_user_data_to_csv.aspx

http://social.msdn.microsoft.com/forums/en-US/netfxbcl/thread/729d1214-37f5-4330-9208-bc4d9d695ad0/


Sample Code :

provide your
LDAP_Server_URL ,
ExportAttributes tags
,FilterValue

//  *************************************************
//          Setting connection to LDAP Server
//  *************************************************
try {
    q = "";
strScope="Subtree";

    cmd = CreateObject("ADODB.Command");
    cn = CreateObject("ADODB.Connection");
    rs = CreateObject("ADODB.Recordset");
    cn.open("Provider=ADsDSOObject;");
    cmd.activeconnection = cn;
    if ((strRoot == "")) {
        objRoot = GetObject(LDAP_Server_URL);
        strRoot = objRoot.GET("defaultNamingContext");
    }
    cmd.commandtext = ("<LDAP://" 
                + (strRoot + (">;" 
                + (strFilter + (";" 
                + (strAttributes + (";" + strScope)))))));
    cmd.properties["page size"] = 1000;
    rs = cmd.EXECUTE;
}
catch (Exception ex) {
    Console.WriteLine("Error in setting Active Directory Connection and Command....Press any key to quit");
    Console.ReadLine();
    return;
}

Open in new window



rs will contain all tags as you set in "strAttributes "...put that into datatable and read them one by one
0
 
LVL 8

Expert Comment

by:johny_bravo1
ID: 39243964
0
 

Author Comment

by:websss
ID: 39262098
I've tried following this code
http://www.aspdotnet-suresh.com/2011/03/how-to-get-userdetails-from-active.html

But System.directoryServices isn't valid (unknown namespace)
0

Featured Post

Problems using Powershell and Active Directory?

Managing Active Directory does not always have to be complicated.  If you are spending more time trying instead of doing, then it's time to look at something else. For nearly 20 years, AD admins around the world have used one tool for day-to-day AD management: Hyena. Discover why

Question has a verified solution.

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

Did you know that more than 4 billion data records have been recorded as lost or stolen since 2013? It was a staggering number brought to our attention during last week’s ManageEngine webinar, where attendees received a comprehensive look at the ma…
Here's a look at newsworthy articles and community happenings during the last month.
Microsoft Active Directory, the widely used IT infrastructure, is known for its high risk of credential theft. The best way to test your Active Directory’s vulnerabilities to pass-the-ticket, pass-the-hash, privilege escalation, and malware attacks …
Sometimes it takes a new vantage point, apart from our everyday security practices, to truly see our Active Directory (AD) vulnerabilities. We get used to implementing the same techniques and checking the same areas for a breach. This pattern can re…
Suggested Courses

801 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