Convert Csv To Ldif

Edit the csv

You have to change the attribute names (first line csv) in ldap attribute names. http://www.yolinux.com/TUTORIALS/LinuxTutorialLDAP-GILSchemaExtension.html

example csv file

dn,ObjectClass,title,cn,sn,postalAddress,postalCode,l,telephoneNumber,mail
"cn=Kristof Vansant,ou=Contactlist,dc=domain,dc=com",inetOrgPerson,ICT,Kristof Vansant,Vansant,Somewhere 1,3000,Gent,05 455 54 74,05 482 05 68,moc.thgir|haey#moc.thgir|haey
"cn=Lupus Vansant,ou=Contactlist,dc=domain,dc=com",inetOrgPerson,ICT,Lupus Vansant,Vansant,Somewhere 1,3000,Gent,05 455 54 74,,moc.thgir|2haey#moc.thgir|2haey

the character + in dn is not allowed use & instead

Warning: dn,ObjectClass, cn and sn must be filled in, the rest is optional!!

cn name must be unique (KriStoF and kristof are the same!)

The CSV should be in a format where the first row has column headings and the first column
should be the DN

You should know that outlook will search ldap like this: (&(|(mail=%s*)(cn=%s*)(sn=%s*)(givenName=%s*)))

We use the inetOrgPerson object because this has all the attributes we need.
The cn in the dn and the other cn on the same line must match.

convert the csv to ldif

download perl

Pick the latest win32 MSI install release
http://www.activestate.com/store/activeperl

Warning: Don’t install on windows 2003 running IIS6 (seems to be fixed but haven't tested my self!) http://bugs.activestate.com/show_bug.cgi?id=68446

download csv2ldif

To convert the cvs file to ldif you need following tool:
http://users.pandora.be/foryourneeds/ldap/csv2ldif.zip

convert csv to ldif

You need to use the AddData2v2.pl version if you have fields in the csv with no data.
Is needed for example if you don't have the telephone number of all the people in the list.

AddData2v2.pl

If your csv file has ; instead of , as seperation you have to edit AddData2v2.pl and change

$separator=','; in $separator=';';

convert ASCII to UTF-8

The ldif file is now in ASCII format. Ldap won't be able to import data with special letters like é.
You have to convert the ASCII file to UTF-8 first.

download libiconv

http://gnuwin32.sourceforge.net/downlinks/libintl.php
http://gnuwin32.sourceforge.net/downlinks/libiconv.php

convert ASCII to UTF-8

in cmd type

path=%path%;C:\Program Files\GnuWin32\bin
iconv -f iso8859-1 -t utf-8 foo.ldif > foonew.ldif

Sources
http://www.novell.com/coolsolutions/tools/14462.html
http://www.openldap.org/lists/openldap-software/200408/msg00458.html
http://technet2.microsoft.com/Office/en-us/library/ff54b078-5bf8-4f24-8573-5607339c96701033.mspx?mfr=true

Unless otherwise stated, the content of this page is licensed under Creative Commons Attribution-Share Alike 2.5 License.