How to list all AD Users with emailaddress over all domains

Posted on 2009-07-10
Last Modified: 2012-05-07

my problem is, that I have to create a list with all Active Directory users over all domains with a specific email domain e.g. "". When I ask the Global Catalog I it works good, but what informations are missing in the GC? When I perform a normal LDAP search, I get only the entries in the local AD domain partition.

So I think the best way would be a LDAP search including all child domains.

This is my first question here, so please advise me of my faults.
wscript.echo  "Looking for GC"

dim oCont, oGC

Set oCont = GetObject("GC:")

For Each oGC In oCont

    strGCPath = oGC.ADsPath


wscript.echo "strGCPath=" & strGCPath, 3

wscript.echo "Querying AD for Objects" & strGCPath

Set oConnection = CreateObject("ADODB.Connection")

Set oRecordset = CreateObject("ADODB.Recordset")

Set oCommand = CreateObject("ADODB.Command")

oConnection.Provider = "ADsDSOObject"  'The ADSI OLE-DB provider

oConnection.Open "ADs Provider"

oCommand.ActiveConnection = oConnection

oCommand.Properties("Page Size") = 100

oCommand.CommandText = "<" & strGCPath & ">;" & _

	"(mail=*;" & _

	"distinguishedName,ObjectClass,displayName,mail" & _


Set oRecordset = oCommand.Execute

wscript.echo "Done Total Records found:" & oRecordset.recordcount

do until oRecordset.EOF

	wscript.echo "---- Infos aus dem ADO-Recordset ----"

	wscript.echo "Klasse:" & lcase(join(oRecordset.Fields("ObjectClass"),","))


	wscript.echo "distinguishedName:" & oRecordset.Fields("distinguishedName")

	wscript.echo "displayName      :" & oRecordset.Fields("displayName")

	wscript.echo "Mail             :" & oRecordset.Fields("mail")

	wscript.echo "---- Infos aus dem gebundenen Object ----"

	set oObject = GetObject("LDAP:// " & oRecordset.Fields("distinguishedName"))

	wscript.echo "name          :" &

	wscript.echo "SamAccountName:" & oObject.samAccountName



Open in new window

Question by:D-CPA
  • 2
LVL 65

Accepted Solution

RobSampson earned 125 total points
ID: 24821654
Hi, welcome to EE!

First off, I'm not sure what you mean when you ask "what informations are missing in the GC?"

Perhaps you could use part of the EnumDomains Sub from here:

to list all of your child domains, then you could just do a normal LDAP search on each of those....

If you need help with that, I can give it a shot tomorrow.



Author Closing Comment

ID: 31601979
Thanks a lot, looks good. I will try now to combine my script with this solution.
LVL 65

Expert Comment

ID: 24822549
No problem. FYI, you don't need to close a question straight away if you're still working on it. Most of us experts are glad to assist you further in completing your task.



Featured Post

Netscaler Common Configuration How To guides

If you use NetScaler you will want to see these guides. The NetScaler How To Guides show administrators how to get NetScaler up and configured by providing instructions for common scenarios and some not so common ones.

Question has a verified solution.

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

Mapping Drives using Group policy preferences Are you still using old scripts to map your network drives if so this article will show you how to get away for old scripts and move toward Group Policy Preference for mapping them. First things f…
Not long ago I saw a question in the VB Script forum that I thought would not take much time. You can read that question (Question ID  ( Here (http…
This tutorial will walk an individual through the process of configuring their Windows Server 2012 domain controller to synchronize its time with a trusted, external resource. Use Google, Bing, or other preferred search engine to locate trusted NTP …
This Micro Tutorial hows how you can integrate  Mac OSX to a Windows Active Directory Domain. Apple has made it easy to allow users to bind their macs to a windows domain with relative ease. The following video show how to bind OSX Mavericks to …

920 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

Need Help in Real-Time?

Connect with top rated Experts

17 Experts available now in Live!

Get 1:1 Help Now