
03-25-2008, 03:22 PM
|
|
|
Retrieving info from ADSI and displying on text file
Hi guys. I have an AD group which has lots of "User" and "Contact" type objects. My goal is to retrieve certain fields of information from each "Contact" object and store them in a text file, one line per contact object.
So for example if there are two contact objects John and Sally, i want the information to be displayed as this:
Quote:
John, Marketing, Manager, 212-222-1234
Sally, Accounting, Director, 413-435-4321
|
And so on and so forth.
I have no coding experience, but i have still written a code based on tips ive found in books and on the web. The code is not tested yet. Would any of you guys be kind enough to go through it and give me some tips please? Thank you all so much.
Quote:
Option Explicit
On Error Resume Next
Dim qQuery, objConnection, objCommand, objRecordSet
Dim objFSO, objFolder, objShell, objTextFile, objFile, filePath
qQuery = "<LDAP://OU=ABCD,OU=OFFICES,DC=CA,DC=ABCD,DC=NET>;" & _ "(objectCategory=Contact);"
Set objConnection = CreateObject("ADODB.Connection")
Set objCommand = CreateObject("ADODB.Command")
objConnection.Open "Provider=ADsDSOObject;"
objCommand.ActiveConnection = objConnection
objCommand.CommandText = qQuery
Set objRecordSet = objCommand.Execute
'Create File system object
Set objFSO = CreateObject("Scripting.FileSystemObject")
set objFile = nothing
set objFolder = nothing
set filePath = "C:\Folder\textfile.txt"
' OpenTextFile Method needs a Const value
' ForAppending = 8 ForReading = 1, ForWriting = 2
Const ForAppending = 8
Set objTextFile = objFSO.OpenTextFile _
(filePath, ForAppending, True)
'Output worker
While Not objRecordSet.EOF
' Writes to file
objTextFile.WriteLine(objRecordSet.Get("telephoneN umber") & ", "
& objRecordSet.Get("department") & ", "
& objRecordSet.Get("title") & ", "
& objRecordSet.Get("physicalDeliveryOfficeName") & ", "
& objRecordSet.Get("facsimileTelephoneNumber") & ", "
& objRecordSet.Get("mobile") & ", "
& objRecordSet.Get("proxyAddress") & ", "
& objRecordSet.Get("initials") )
objRecordSet.MoveNext
Wend
objConnection.Close
|
|