How to list all AD Users with emailaddress over all domains

Hello,

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. "@xy.de". 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
Next
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=*@xy.de);" & _
	"distinguishedName,ObjectClass,displayName,mail" & _
	";subtree"
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 	
	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          :" & oObject.name
	wscript.echo "SamAccountName:" & oObject.samAccountName
	oRecordset.MoveNext
loop

Open in new window

D-CPAAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

RobSampsonCommented:
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:
http://www.rlmueller.net/Programs/DocumentForest.txt

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.

Regards,

Rob.
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
D-CPAAuthor Commented:
Thanks a lot, looks good. I will try now to combine my script with this solution.
0
RobSampsonCommented:
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.

Regards,

Rob.
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Active Directory

From novice to tech pro — start learning today.