Beefy Boxes and Bandwidth Generously Provided by pair Networks
No such thing as a small change
 
PerlMonks  

Adding a list of contacts to Exchange Address book.

by thunders (Priest)
on Dec 10, 2003 at 18:52 UTC ( #313813=perlquestion: print w/ replies, xml ) Need Help??
thunders has asked for the wisdom of the Perl Monks concerning the following question:

I am looking for a way to add a large list of people to my companies global address book. I'd like to use perl if possible. We run Exchange 2000 on Windows 2000 Pro , and I haven't been able to find any documentation on how to do that in any language, without logging onto the mail server and manually entering each one into the the "Active directory Users and Computers" tool.

I looked at modules like Win32::NetAdmin, Win32::OLE, IDG::Win32::ActiveDirectory. But I can only find methods to add actual domain users, not simple email contacts. I also looked at Net::LDAP to import via Active Directory's LDAP interface, but recreating an LDAP schema for contacts seems like overkill for this task. Has anybody here come up with a way to automate this?

Comment on Adding a list of contacts to Exchange Address book.
Re: Adding a list of contacts to Exchange Address book.
by idsfa (Vicar) on Dec 10, 2003 at 19:03 UTC

    Yes, Microsoft has. The tool you want is the Exchange Administrator Bulk Import Tool (FAQ), which takes a CSV as input (and can be run in batch mode from the command line -- see the FAQ). Perl has plenty of CSV related tools.

    Otherwise, the Net::LDAP route is the pure perl way.


    My parents just came back from a planet where the dominant life form had no
    bilateral symmetry, and all I got was this stupid F-Shirt.
Re: Adding a list of contacts to Exchange Address book.
by SquireJames (Monk) on Dec 11, 2003 at 01:12 UTC
    I haven't done exactly what you're looking for, but I do a lot of stuff with Active Directory by using Net::LDAP and Win32::OLE. Net::LDAP is probably a bit easier to use, whilst Win32::OLE allows you to do some stuff without authenticating (allowing pass through, if you will).

    An excellent resource for this type of stuff is the book "Managing Enterprise Active Directory Services" by Robbie Allan and Rickard Puckett, which contains examples of anything that you'd want to do in both VB and Perl.

    I haven't creatd contact objects, only user ones, but I think that what I've suplied you with below should work.

    use strict; use Net::LDAP; use Net::LDAP::Entry; my $ldap_prov = *servername* print ("\nUsername for connection: "); my $username = <STDIN>; print ("\nPassword: "); my $password = <STDIN>; chomp $username; chomp $password; my $ldap = Net::LDAP->new($ldap_prov) || die; my $bind = $ldap->bind($user, password => $password, $version => 3); my $contact = Net::LDAP::Entry->new(); $contact->dn("cn=$contact,cn=contacts,dc=aaa,dc=com); $contact->add(objectclass -> 'contact'); # I'm not sure if you'll need + to pass anything else here. Normally when you setup a user, you'll +need to also pass the SAMAccountName attribute.... my $result = $contact->update($ldap); $ldap->unbind;
    This (should) create the contact, although it may take some fiddling to get spot on. I've only ever used it to create users, but theoretically speaking it should be fine for contacts. Let me know how you go with it if you choose to try and code it.

    Obviously before you unbind and after you update, you could add any further fields that you want to, or you could just add more attributes during the initial create.

      Thanks that code works perfectly, I tested it with the following and it created my contact, "SAMAccountName" isn't a required field for contacts, all they really seem to need is the "dn" and "objectClass" fields.
      use strict; use Net::LDAP; use Net::LDAP::Entry; my $ldap_prov = "server"; my $ldap = Net::LDAP->new($ldap_prov) || die; print ("\nUsername for connection: "); my $username = <STDIN>; print ("\nPassword: "); my $password = <STDIN>; chomp $username; chomp $password; my $bind = $ldap->bind($user, password => $password, $version => 3); my $contact = Net::LDAP::Entry->new(); my $name = "Bob Smith"; my $email = 'bobs@website.com'; $contact->dn( "cn=$name,ou=Website External Contacts," ."dc=corp,dc=website,dc=com" ); $contact->add(objectClass => 'contact'); $contact->add(name => $name); $contact->add(displayName => $name); $contact->add(mail => $email); $contact->add(targetAddress => "SMTP:$email"); my $result = $contact->update($ldap); $ldap->unbind;
        sorry i'm not a script person. there might be something that i'm missing there. it looks like that you are still importing one contact at a time, and need to fill in those names and email address in the script one by one. How then can I do the bulk of a thousand at one go, if their names and email addresses are already in an excel file?

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: perlquestion [id://313813]
Approved by coreolyn
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others scrutinizing the Monastery: (9)
As of 2014-11-26 17:28 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    My preferred Perl binaries come from:














    Results (172 votes), past polls