http://qs1969.pair.com?node_id=313942


in reply to Adding a list of contacts to Exchange Address book.

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.