vbscript to enumerate active directory

Microsoft Windows xp pro with sp3 multil...
January 22, 2011 at 10:47:16
Specs: Windows XP
I would like to create a script to enumerate all accounts within the active directory forest. I would also like to capture the following:

First Name
Last Name
email address

Does anyone out there have any pointers as to how to go about doing this? I am guessing that this information should be fairly easy to collect using wscript and some sort of VBS script.

My knowledge of vbs scripts is very limited.


See More: vbscript to enumerate active directory

Report •

January 25, 2011 at 13:05:23
I'm not sure what you want to do with this information, nor do I have any idea how long this will run, nor the size of the resulting .csv, and you never respond after asking your question, but whatever. It gives me an excuse to see how rusty my ADSI skills are. (Very)
Set fOut = CreateObject("Scripting.FileSystemObject").OpenTextFile("forestDump.csv", 2, True)
Set gc = GetObject("GC:")
For Each domain In gc
  With CreateObject("ADODB.Command")
    .ActiveConnection = "Provider=ADsDSOObject"
    .Properties("Chase referrals") = &H60
    .CommandText = "<LDAP://" & domain.Name & ">;(&(objectClass=user)(objectCategory=person)(!Name=*$));" _
        & "Name,ADsPath,GivenName,sn,telephoneNumber,mail;subtree"
    Set rs = .Execute
  End With
  Do Until rs.EOF
    out rs.Fields
WScript.Echo "Done"

Sub out(fields)
  For Each f In fields
    line = line & ",""" & f & """"
  Next 'f
  fOut.WriteLine Mid(line, 2)
End Sub

EDIT: Also, I took "address" to mean the LDAP address.
How To Ask Questions The Smart Way

Report •
Related Solutions

Ask Question