Link to home
Start Free TrialLog in
Avatar of mechanicus01
mechanicus01Flag for Mexico

asked on

Script to create email enabled contacts from csv file

Hello I need a vbs script to create email enabled contacts for exchange 2000 from a csv file.

Thanks much
SOLUTION
Avatar of mechanicus01
mechanicus01
Flag of Mexico image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Change line no 30 to following, strDNSDomain does not exist

Set objOU = GetObject("LDAP://"& strContainer & "," & strDNS)
Avatar of mechanicus01

ASKER

Yes, sorry I don´t know how that got in there. Do you know of any tool, that will help in debugging syntax errors ??

I´m still getting the same error.

=======================


Const ForReading = 1

strSourceFile = "contacts.csv"
strContainer = "OU=comarca," ' Insert the name of the OU where the accounts will be created

' Section to attach to Active Directory
Set objRoot = GetObject("LDAP://rootDSE")
strDNS = objRoot.Get("defaultNamingContext")
Set objDomain = GetObject("LDAP://" & strDNS)

'Reads the Source file
Set objFSO = CreateObject("Scripting.FileSystemObject")
Set objFile = objFSO.OpenTextFile(strSourceFile, ForReading)
strAllLines = objFile.ReadAll
objFile.Close

arrLines = Split(strAllLines,VbCrLf)

For Each strLine In arrLines
      If strLine <> "" Then
            arrDetails = split(strLine,",")
            
            strContactName = "cn=" & arrDetails(2)
            strFirstName = arrDetails(0)
            strLastName = arrDetails(1)
            strMail = arrDetails(3)
            If strMail <> "" Then
                  If InStr(strMail, "@")Then
                        ' Section to create the contact
                        Set objOU = GetObject("LDAP://"& strContainer & "," & strDNS)
                        Set objContact = objOU.Create("contact", strContactName)
                        objContact.Put "Mail", strMail
                    objContact.Put "givenName", strFirstName
                    objContact.Put "sn", strLastName
                        ' Section to prevent errors caused by blank email address
                        objContact.SetInfo
                        
                        Set objRecip = objContact
                        FwdAddress = "smtp:" & strMail
                        objRecip.MailEnable FwdAddress
                        objContact.SetInfo
                  End If
            End If
      End If
Next
There is no tool I am aware of...

The error may be because of an additional comma

Remove "," after comarca and try
strContainer = "OU=comarca" ' Insert the name of the OU where the accounts will be created
Ok... Now i get another error.

Script: C:\contacts.vbs
Line: 30
Char: 5
Error: There is no such object on the sever.
Code: 80072030
Source: (nul)

 I know that the OU exists.
OK, I changed it to
strContainer = "OU=Contacts"

and now I get
Script: C:\contacts.vbs
Line: 306
Char: 5
Error: There is a naming violation
Code: 80072037
Source: (nul)
Sorry, line 36

Script: C:\contacts.vbs
Line: 36
Char: 5
Error: There is a naming violation
Code: 80072037
Source: (nul)
Ok.. so I figured those out.. with this one i´m stuck.

Script: C:\contacts.vbs
Line: 44
Char: 11
Error: Expected `Next`
Code: 800A03FC
Source: Microsoft VBScript compilation error
ASKER CERTIFIED SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
:) yes, that was it.. I also ran into a few other errors but I managed to get thru... I got it to work :)
Thank you for your help!
Thank you!