• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 966
  • Last Modified:

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
0
mechanicus01
Asked:
mechanicus01
  • 8
  • 3
2 Solutions
 
mechanicus01Author 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
 
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
Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
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
 
prashanthdCommented:
may be you missed Next on last line, can you post the code?
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

Featured Post

What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

  • 8
  • 3
Tackle projects and never again get stuck behind a technical roadblock.
Join Now