mechanicus01
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
Thanks much
SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
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("defaultNaming Context")
Set objDomain = GetObject("LDAP://" & strDNS)
'Reads the Source file
Set objFSO = CreateObject("Scripting.Fi leSystemOb ject")
Set objFile = objFSO.OpenTextFile(strSou rceFile, 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
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("defaultNaming
Set objDomain = GetObject("LDAP://" & strDNS)
'Reads the Source file
Set objFSO = CreateObject("Scripting.Fi
Set objFile = objFSO.OpenTextFile(strSou
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
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
ASKER
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.
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.
ASKER
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)
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)
ASKER
Sorry, line 36
Script: C:\contacts.vbs
Line: 36
Char: 5
Error: There is a naming violation
Code: 80072037
Source: (nul)
Script: C:\contacts.vbs
Line: 36
Char: 5
Error: There is a naming violation
Code: 80072037
Source: (nul)
ASKER
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
Script: C:\contacts.vbs
Line: 44
Char: 11
Error: Expected `Next`
Code: 800A03FC
Source: Microsoft VBScript compilation error
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
:) 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 for your help!
ASKER
Thank you!
Set objOU = GetObject("LDAP://"& strContainer & "," & strDNS)