Active Directory query for username, first name, last name and email

Forgive my ignorance, I know little about AD (give a lone request with AD or googling for this). I would like to get a list of all users in a specific domain, their first name, last name and email identifiers. Can a network administrator (or support service in my case) do this? My other option: I have the usernames in the excel sheet, the full name in another text file (among other data - for example, XXXyy, FirstName LastName - I would need to split, parse it to extract the name) and send it by email to another file, and not one of them is fine. There may also be some missing data :(

What would be the best way with Querying AD?

Edit: Maybe I should be more specific. If I saw what my network administrator would do to get me this information, what would he do?

+7
active-directory
source share
2 answers

Active Directory provides a query interface through OLE DB and ADO. The provider is "ADsDSOObject", the query syntax is as follows:

<LDAP: // DC = my-domain, DC = COM>; (ObjectType = user); GivenName, sn

Excel does not have an ADO built-in client unless you use VBA code.

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 asks for the username and surname of all users in your domain. Put your domain name in the third line. Then save it as a .js file and execute it:

 cscript adquery.js >a.txt 

And you will get a text file called a.txt with the names of your users, separated by a comma. Import it into Excel or something like that.

+4
source share

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

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

Hope this helps!

+4
source share

All Articles