Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations TouchToneTommy on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Export contact list in Active Directory to Access 1

Status
Not open for further replies.

jay24k

MIS
May 12, 2004
32
US
I posted in LDAP but I don't think it can be done that way...

I've searched everywhere and I'm unable to find it. Server is 2000 and Exchange 2000 as well. I have a OU Group that is primarily for special email accounts and mobile contacts where the contacts appear in the ALL Contacts listing in Outlook for everyone. I've tried to pull those in a vbscript but that doesn't appear to work. What I would like is for the users in our organization that doesn't have a user account, but that does have a cell phone, to place it as a contact. Right now it shows up fine if you search your email client as all contacts.

What I need to do next is have it so every week, I can run a script or something that pulls these updated values into an accesss database. Mainly, name, number, department, title (info from the contact) I have this working fine from regular AD users but not contacts. These contacts aren't in user mailboxes but globaly.

Any ideas on the best way to do this?
 
Well I thought maybe some here might see this and give some insight. I export my users with a similiar statement:

.CommandText = _
"Select userAccountControl, distinguishedName," & _
" sAMAccountname, displayName, telephonenumber" & _
" FROM 'LDAP://" & strDNSDomain & "'" & _
" WHERE objectCategory = 'person' AND" & _
" objectClass = 'user'" & _
" ORDER BY displayName"

So I thought by changing my object class to contact, it should pull it up right? When I do a ldifde and export the whole active directory, it shows them as a contact class.

For example, the export of ldifde on the ones I want to export which are really just a contact in a OU is the following.

dn: CN=testcontact,CN=users,DC=mydomain,DC=com
changetype: add
ObjectClass: top
ObjectClass: person
ObjectClass: organizationalPerson
ObjectClass: contact
cm: testcontact
sn: contact
givenName: Test
distinguishedName: CN=testcontact,CN=users, DC=mydomain,DC=com
instanceType: 4
whencreated: somedate
whenchanged: ditto
USNCreated: somenumber
USNChanged: Ditto
name: testcontact
ObjectGUID:: someoddcomboletternumber
ObjectCategory: CN=Person,CN=Schema,CN=Configuration,DC=mydomain,DC=com

Maybe I need to do more a selective search on sn?

I'll test some more but would really love if anyone had any quick ideas. I just want to pull contact name, department, title and number.

Thanks a ton.
 
Well either no one here wanted to help or no one knew but after a good day of messing around, I finally am able to pull any contact information within exchange/active directory from the active directory listing. I read on here it can't be done but I could do it in ldifde by choosing the right OU. Here is my script if anyone else would like it. I get some help here so I'm contributing back. I put my mobile in the telephone number section however if you want to use the mobile area, I believe the syntax is just mobile. Hope this helps.

'6/2/04
'Jason Keen jay24k@comcast.net
' This is a script that pulls contacts from the Mobile OU Group.
Dim objconnection, objRecordset
Dim oContainer
Const AccessDatabase = "c:\intranet1.mdb"
Const Accesstable = "phonelist"

'Database Connections
Set objConnection = CreateObject("ADODB.Connection")
Set objRecordset = CreateObject("ADODB.Recordset")
objConnection.Open "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=\\server\c$\intranet1.mdb"
objRecordset.Open AccessTable, objConnection, 3, 3

' This needs to be set to your OU group you want to query and domain info.
Set oContainer=GetObject("LDAP://OU=Mobile Contacts,DC=domain, DC=com")
QueryUsers oContainer
Set oContainer = Nothing
WScript.Echo "Finished"
WScript.Quit(0)
Sub QueryUsers(oCont)
Dim oUser
For Each oUser In oCont
Select Case LCase(oUser.Class)
Case "contact"

'Choose the records you want added. DisplayName looks better then Name as that shows CN=
objRecordset.AddNew
objRecordset("Name") = oUser.DisplayName
objRecordset("Department") = oUser.Department
objRecordset("MobilePhone") = oUser.telephonenumber
objRecordset("Title") = oUser.title
objRecordset("ImportedfromAD") = "True"

'Update record
objRecordset.update

End Select
Next
End Sub

'Close Connections
objRecordsetDB.Close
objConnectionDB.Close
 
Thanks for posting the solution back here.

[blue]"Well, once again my friend, we find that science is a two headed beast. One head is nice, it gives us aspirin and other modern conveniences,...but the other head of science is BAD! Oh, beware the other head of science, Arthur; it bites!!" - The Tick[/blue]
 
Just as a second note. My first script checks to see if importedfromad = true. If it does, it will delete all entries when it rebuilds. IF something doesn't make sense here, it's probably because I have it in use in a prior script.

 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top