Solved

mail enabled contacts script

Posted on 2010-09-08
8
881 Views
Last Modified: 2012-05-10
I need a script to create a few hundred mail enabled contacts in AD. Anyone have an easy scrip to accomplish this? I will have all the names in a .csv for the script to call upon.

Thxs
0
Comment
Question by:KratosDefense
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 4
  • 3
8 Comments
 
LVL 53

Expert Comment

by:Will Szymkowski
ID: 33632720
Take a look at this PAQ as it should help with this process...
http://www.experts-exchange.com/Programming/Languages/Visual_Basic/Q_22015257.html

Hope this helps~!
0
 
LVL 5

Expert Comment

by:MaxSoullard
ID: 33634896
Hi
Can you give a line of your csv, so I can create a script that can use it
0
 
LVL 5

Expert Comment

by:MaxSoullard
ID: 33635185
Try this code. The source csv is expected to be:

contact name,email@domain.com,description

Just instantiate the following variables:

strSourceFile = "SOURCE FILE PATH"
strContainer = "OU=Suppliers"


Const ForReading = 1

strSourceFile = "SOURCE FILE PATH"
strContainer = "OU=Suppliers" ' 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(0)
		strMail = arrDetails(1)
		strDescription = arrDetails(2)
		' Section to create the contact
		Set objOU = GetObject("LDAP://"& strContainer & "," & strDNS)
		Set objUser = objOU.Create("contact", strContactName)
		objUser.Put "Description", strDescription
		objUser.Put "Mail", strMail
		' Section to prevent errors caused by blank email address
		If strMail <> "" Then
			objUser.SetInfo
		End If
	End If
Next

Open in new window

0
NEW Veeam Agent for Microsoft Windows

Backup and recover physical and cloud-based servers and workstations, as well as endpoint devices that belong to remote users. Avoid downtime and data loss quickly and easily for Windows-based physical or public cloud-based workloads!

 

Author Comment

by:KratosDefense
ID: 33638889
Max, here is an example of the .csv. I have 4 fields, givenname, sn, displayname, mail.

will this work with the script you provided?
contact.jpg
0
 
LVL 5

Expert Comment

by:MaxSoullard
ID: 33644551
This should work with your CSV, please try it first on a test environment. Let me know how it goes.
Const ForReading = 1

strSourceFile = "SOURCE FILE PATH"
strContainer = "OU=Suppliers" ' 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)
		' 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
		If strMail <> "" Then
			If InStr(strMail, "@")Then
				objContact.SetInfo
			End If
		End If
	End If
Next

Open in new window

0
 

Author Comment

by:KratosDefense
ID: 33651281
Max I ran the script, it created the contact object; however, it doesnt mail-enable them. Is it possible to have the script mail enable the contacts or is that something Im going to need to do through exchange/AD? Im running exchange 2003; unfortunatly, doesnt look like I can select multiple contacts and mail enable them; need to do it one by one. Hola and thxs
0
 
LVL 5

Accepted Solution

by:
MaxSoullard earned 500 total points
ID: 33661669
try now
Const ForReading = 1

strSourceFile = "SOURCE FILE PATH"
strContainer = "OU=Suppliers" ' 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

Open in new window

0
 

Author Closing Comment

by:KratosDefense
ID: 33686363
thxs
0

Featured Post

Revamp Your Training Process

Drastically shorten your training time with WalkMe's advanced online training solution that Guides your trainees to action.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

This article outlines the process to identify and resolve account lockout in an Active Directory environment.
This article explains the steps required to use the default Photos screensaver to display branding/corporate images
In this Micro Video tutorial you will learn the basics about Database Availability Groups and How to configure one using a live Exchange Server Environment. The video tutorial explains the basics of the Exchange server Database Availability grou…
A short tutorial showing how to set up an email signature in Outlook on the Web (previously known as OWA). For free email signatures designs, visit https://www.mail-signatures.com/articles/signature-templates/?sts=6651 If you want to manage em…

738 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question