views:

455

answers:

2

Pardon my ignorance, I do not know much about AD (let lone querying with AD or googling for that). I would like to get a list of all the users in a particular domain, their first name, last name and email ids. Would a network admin (or help desk in my case) be able to do that ? My other option: I have the usernames in an excel sheet, Full name in another text file (amongst other data - say XXXyy , FirstName LastName- I would have to split,parse it to extract the name) and email in another file and none of them are in order. There might be some missing data too :(

What would be the best way to go about it with Querying AD ?

Edit:May be I should be more specific. If I was seeing what my network admin would be doing to get me this info, what would he be doing ?

+1  A: 

If you're using the .NET platform, I would suggest looking into the System.DirectoryServices namespace, which "provides easy access to Active Directory Domain Services from managed code."

MSDN also provides code samples for performing common tasks using System.DirectoryServices, available in both VB and C#. If you're familiar with one of these languages, you should hopefully be able to glean what you need (at least to get started, and then perhaps be able to ask other, more specific questions here on SO) from these examples.

Hope this helps!

Donut
A: 

Active Directory exposes query interface via OLE DB and ADO. The provider is "ADsDSOObject", the query syntax goes like this:

<LDAP://DC=my-domain,DC=com>;(objectType=user);givenname,sn

Excel does not have a built-in ADO client, unless you code in VBA.

UPDATE: wrote a simple JavaScript query script for you:

var conn = new ActiveXObject("ADODB.Connection");
conn.Open("Provider=ADsDSOObject");
var rs = conn.Execute("<LDAP://DC=your-domain,DC=com>;(objectClass=user);sn,givenname");
var i;
if(!rs.EOF)
{
    rs.MoveFirst();
    while(!rs.EOF)
    {

        WScript.Echo(rs.Fields.Item("givenname")+","+rs.Fields.Item("sn")+"\n");
        rs.MoveNext();
    }
}

It queries the fiest and last name of all users in your domain. Place your domain name in the third line. Then save it as a .js file, and execute thusly:

cscript adquery.js >a.txt

And you'll end up with a text file called a.txt, with the names of your users, comma-separated. Import it into Excel or something.

Seva Alekseyev