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.
Seva Alekseyev
source share