Patrick,
Tive que usar VBScript para escrever um arquivo csv e obter as informações de todos... Não sou um especialista em VBScript, mas um colega de trabalho tinha um script que pude modificar para minhas necessidades:
Const ADS_SCOPE_SUBTREE = 2
Set objFSO = CreateObject("Scripting.FileSystemObject")
objFSO.CreateTextFile("UserFile.csv")
Set objFile = objFSO.OpenTextFile("UserFile.csv", 2)
Set objConnection = CreateObject("ADODB.Connection")
Set objCommand = CreateObject("ADODB.Command")
objConnection.Provider = "ADsDSOObject"
objConnection.Open "Active Directory Provider"
Set objCommand.ActiveConnection = objConnection
objCommand.CommandText = "Select EmployeeID, mail from 'LDAP://DC=whatever,DC=us'" & _
" where objectCategory='person' and objectClass='user' and employeeID = ' 99 '"
objCommand.Properties("Page Size") = 10
objCommand.Properties("Timeout") = 30
objCommand.Properties("Searchscope") = ADS_SCOPE_SUBTREE
objCommand.Properties("Cache Results") = False
Set objRecordSet = objCommand.Execute
objRecordSet.MoveFirst
objFile.WriteLine("EmployeeID,Email")
Do Until objRecordset.EOF
If Not IsNull(objRecordset.Fields("mail").Value) Then
iRec = iRec + 1
objfile.write (objRecordset.Fields("EmployeeID") & ", ")
If InStr(objRecordset.Fields("mail"), "@") = 0 Then
objfile.write (", ")
Else: objfile.write (LCase(Left(objRecordset.Fields("mail"), InStr(objRecordset.Fields("mail"), "@") - 1)) & ", ")
End If
objfile.WriteLine ("")
End If
objRecordset.MoveNext
Loop
objFile.Close
msgbox "¡HECHO!"