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
LVL 1
mechanicus01Asked:
Who is Participating?
 
prashanthdConnect With a Mentor Commented:
may be you missed Next on last line, can you post the code?
0
 
mechanicus01Connect With a Mentor Author Commented:
I am using a vbs script I found here in EE but I am getting an 80005000 error:

Script: C:\contacts.vbs
Line: 30
Char: 5
Error: 0x80005000
Code: 80005000
Source: (nul)

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

Const ForReading = 1

strSourceFile = "contacts.csv"
strContainer = "OU=Contacts," ' 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 = 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 & "," & strDNSDomain)
                        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
0
 
prashanthdCommented:
Change line no 30 to following, strDNSDomain does not exist

Set objOU = GetObject("LDAP://"& strContainer & "," & strDNS)
0
Free Tool: Site Down Detector

Helpful to verify reports of your own downtime, or to double check a downed website you are trying to access.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

 
mechanicus01Author 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
0
 
prashanthdCommented:
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
0
 
mechanicus01Author 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.
0
 
mechanicus01Author 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)
0
 
mechanicus01Author Commented:
Sorry, line 36

Script: C:\contacts.vbs
Line: 36
Char: 5
Error: There is a naming violation
Code: 80072037
Source: (nul)
0
 
mechanicus01Author 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
0
 
mechanicus01Author 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!
0
 
mechanicus01Author Commented:
Thank you!
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.