Become a Columnist Microsoft Exchange Site Microsoft Support SiteMSDN Exchange Site

   

Subscribe to OutlookExchange
Anderson Patricio
Ann Mc Donough
Bob Spurzem
Brian Veal
Catherine Creary
Cherry Beado
Colin Janssen
Collins Timothy Mutesaria
Drew Nicholson
Fred Volking
Glen Scales
Goran Husman
Guy Thomas
Henrik Walther
Jason Sherry
Jayme Bowers
John Young
Joyce Tang
Justin Braun
Konstantin Zheludev
Kristina Waters
Kuang Zhang
Mahmoud Magdy
Martin Tuip
Michael Dong
Michele Deo
Mitch Tulloch
Nicolas Blank
Pavel Nagaev
Ragnar Harper
Ricardo Silva
Richard Wakeman
Russ Iuliano
Santhosh Hanumanthappa
Steve Bryant
Steve Craig
Todd Walker
Tracey J. Rosenblath
 
 
Import Active Directory user data into Outlook address books
Page 1 | Page 2 | Page 3 | Page 4
The first step is to run program that creates the CSV file using the data from Active Directory. VB Script is a perfect language to complete this task. 
Here is the list of the program:
 
'EXPORTCONTACTS.VBS
'Version 1.0
'Last Modified 6:54 AM 7/12/2002
'Pavel Nagaev
'pavel.nagaev@cpcpipe.ru
'Summary: Export email addresses to CSV file for import them to Address Book in Outlook 2000
'Usage: cscript //nologo exportcontacts.vbs
 
'*********************************************************************************
'* THIS PROGRAM IS OFFERED AS IS AND MAY BE FREELY MODIFIED OR ALTERED AS *
'* NECESSARY TO MEET YOUR NEEDS. *
'* THE AUTHOR MAKES NO GUARANTEES OR WARRANTIES, EXPRESS, IMPLIED OR OF ANY *
'* OTHER KIND TO THIS CODE OR ANY USER MODIFICATIONS *
'* DO NOT USE IN A PRODUCTION ENVIRONMENT UNTIL YOU HAVE TESTED IN A SECURED LAB *
'* ENVIRONMENT. USE AT YOUR OWN RISK. *
'*********************************************************************************
 
'User parameters
'------------------------------------------------------------------------------------------------------
const FILENAME= "d:\contacts.csv"     'File name for exporting data from  Active Directory
const LDAPQUERY= "LDAP://DC_server/DC=domainname,DC=ru" 'LDAP query to Active Directory, where
'DC_server is the DC server name                                                  'domainname – Your domain name
------------------------------------------------------------------------------------------------------
 
Dim con, com, rs, fso, f
 
   Set fso = CreateObject("Scripting.FileSystemObject")
   Set f = fso.OpenTextFile(FILENAME, 2, True) ' ForReading = 1, ForWriting = 2, ForAppending = 8
 
'Creating the CSV file header
'for Outlook 2000, Outlook Express
 f.Write  "Last Name,First Name,E-mail address" & VbCrLf
 
'for MS Exchange 5.5 f.Write  "Obj-class,Last Name,First Name,E-mail address" & VbCrLf
 
'Connecting to Active Directory
    Set con = CreateObject("ADODB.Connection")
    Set com = CreateObject("ADODB.Command")
    con.Provider = "ADsDSOObject"
    con.Open "Active Directory Provider"
    Set com.ActiveConnection = con
  
‘This query select only not hidden users and contacts 
  com.CommandText = "select givenname, sn,objectCategory,objectClass, mail,msExchHideFromAddressLists _
& from '" & LDAPQUERY & "' where objectClass= 'user' order by sn " _
& or objectClass= 'contact' order by sn"
 
 
    com.Properties("Page Size") = 1000
 
'Run query to Active Directory
 
    Set rs = com.Execute
      
    rs.MoveFirst
    While Not rs.EOF
     Tmail = rs.Fields("mail")
     Tsn   = rs.Fields("sn")
     TgivenName = rs.Fields("givenName")
 
     ‘Write the records to the CDV file which don’t have empty “First Name”, “Last Name”,
             ‘ “Email address”  fields.
 
    If ((Tmail <> "" And Tsn <> "" And _
& TgivenName <> "") And IsNull(rs.Fields("msExchHideFromAddressLists"))) Then
 
       'for Outlook 2000 and Outlook 5.5
        f.Write  Tsn &","& TgivenName & "," & Tmail & VbCrLf
 
       'for Exchange 5.5   f.Write  "Remote," & Tsn &","& TgivenName & ",SMTP:" & Tmail & VbCrLf
 
    End If
        rs.MoveNext
   Wend
   
     rs.Close
     f.Close
 
wscript.quit
 
Import Active Directory user data into Outlook address books
Page 1 | Page 2 | Page 3 | Page 4

Disclaimer: Your use of the information contained in these pages is at your sole risk. All information on these pages is provided "as is", without any warranty, whether express or implied, of its accuracy, completeness, fitness for a particular purpose, title or non-infringement, and none of the third-party products or information mentioned in the work are authored, recommended, supported or guaranteed by Stephen Bryant or Pro Exchange. OutlookExchange.Com, Stephen Bryant and Pro Exchange shall not be liable for any damages you may sustain by using this information, whether direct, indirect, special, incidental or consequential, even if it has been advised of the possibility of such damages.

Copyright Stephen Bryant 2008