This script will create contacts in Active Directory based on a formatted CSV file. It was written to allow automatic synchronisation of contacts using a CSV file as the source.

Download ContactImport.vbs

The usage for the script will echo when run without any parameters.

cscript ContactImport.vbs -f "<File Name>" -o "<Organisational Unit>"  
 [-r] [-s] [-a "<attributes>"] [-d "<delimiter>"] [-n "<Name Foramt>"] [-t]

 -f "<File Name>" – Input File Name (Required)  
 -o "<Organisational Unit>" – Target OU for Contact Objects (Required)  
 -r – Read the Header Line as AD Fields  
 -s – Skip the Header Line  
 -a "<attributes>" – AD Attibutes to write Fields to (Required if not using Header)  
 -d "<delimiter>" – File Delimiter. Uses comma if not specified.  
 -n "<Name Format>" – DisplayName and CN Format by AD Attributes. Uses TargetAddress if not specified.  
 -t – Test Only

Usage examples

Reading data from a CSV using the header line as fields

Example CSV file data:

Chris,Dent,chris.dent@domain.example,123 Somewhere Street,London

The following command will read the header line as the fields to import, then create contacts using givenName and sn as the display name / name.

cscript ContactImport.vbs -f Contacts.csv -o “OU=Contacts,DC=domain,DC=example” -r -n “givenName sn”

The attribute streetAddress appears twice, it will be concatenated using a comma as a delimiter. The streetAddress attribute will contain “123 Somewhere Street, London” in this example.

Defining attributes on the command line

Example CSV file data:


The following command will read the file, then import attributes based on the -a value which must reflect the order of attributes in the import file.

cscript ContactImport.vbs -f Contacts.csv -o "OU=Contacts,DC=domain,DC=example" -a "givenName,sn,targetAddress,company,physicalDeliveryOfficeName"

Because no displayName format has been specified the targetAddress field will be used.

Using a custom file delimiter

Example file data:


In this example the header line contains names that cannot be used as attributes in Active Directory so the script is instructed to ignore it with -s. The fields are defined instead using the -a option. The Delimited is specified with -d.

cscript ContactImport.vbs -f Contacts.txt -o "OU=Contacts,DC=domain,DC=example" -a "givenName,sn,targetAddress" -s -d "|"

As above, because no displayName format is specified the targetAddress is used.