We help IT Professionals succeed at work.

Script to create email enabled contacts from csv file

mechanicus01
mechanicus01 asked
on
983 Views
Last Modified: 2012-05-11
Hello I need a vbs script to create email enabled contacts for exchange 2000 from a csv file.

Thanks much
Comment
Watch Question

Unlock this solution and get a sample of our free trial.
(No credit card required)
UNLOCK SOLUTION
Top Expert 2011

Commented:
Change line no 30 to following, strDNSDomain does not exist

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

Author

Commented:
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
Top Expert 2011

Commented:
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

Author

Commented:
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.

Author

Commented:
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)

Author

Commented:
Sorry, line 36

Script: C:\contacts.vbs
Line: 36
Char: 5
Error: There is a naming violation
Code: 80072037
Source: (nul)

Author

Commented:
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
Top Expert 2011
Commented:
Unlock this solution and get a sample of our free trial.
(No credit card required)
UNLOCK SOLUTION

Author

Commented:
:) 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!

Author

Commented:
Thank you!
Unlock the solution to this question.
Thanks for using Experts Exchange.

Please provide your email to receive a sample view!

*This site is protected by reCAPTCHA and the Google Privacy Policy and Terms of Service apply.

OR

Please enter a first name

Please enter a last name

8+ characters (letters, numbers, and a symbol)

By clicking, you agree to the Terms of Use and Privacy Policy.