Title: Message

Travis, the following should query your GC and return a | (pipe) delimited text file with a few attributes including “mail.” Have a look to see if that’s what you want. This is adapted from scripts found elsewhere, created by folks smarter than me ;-) YMMV

 

Change the dc=myRootDomain to the appropriate root in your environment, and watch for line wraps in the code.

 

 

Dim strLogFile

strLogFile = "c:\temp\user_location.txt"

 

Set fso = CreateObject("Scripting.FileSystemObject")

Set objFile = fso.CreateTextFile(strLogFile, 8, True)

 

Set objConnection = CreateObject("ADODB.Connection")

objConnection.Open "Provider=ADsDSOObject;"

 

Set objCommand = CreateObject("ADODB.Command")

objCommand.ActiveConnection = objConnection

objCommand.Properties("Page Size") = 1000

objCommand.Properties("Sort On") = "sAMAccountName"

objCommand.Properties("Time Limit")      = 0

objCommand.Properties("Timeout")         = 0

 

 

objCommand.CommandText = _

 "<GC://dc=myRootDomain,dc=com>;" & _

      "(&(objectCategory=person)(objectClass=user));" & _

          "sAMAccountName,sn,givenName,mail;subtree"

 

Set objRecordSet = objCommand.Execute

 

While Not objRecordset.EOF

            objFile.Writeline objRecordset.Fields("sAMAccountName").Value & "|" & objRecordset.Fields("sn").Value & "|" & objRecordset.Fields("givenName").Value & "|" & objRecordset.Fields("mail").Value

    objRecordset.MoveNext

Wend

 

objConnection.Close

 

MsgBox "Query has completed. You may view the file c:\temp\user_attribs.txt."

 

 

<mc>

 

Reply via email to