KratosDefense
asked on
mail enabled contacts script
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
Thxs
Hi
Can you give a line of your csv, so I can create a script that can use it
Can you give a line of your csv, so I can create a script that can use it
Try this code. The source csv is expected to be:
contact name,email@domain.com,desc ription
Just instantiate the following variables:
strSourceFile = "SOURCE FILE PATH"
strContainer = "OU=Suppliers"
contact name,email@domain.com,desc
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
ASKER
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
will this work with the script you provided?
contact.jpg
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
ASKER
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
ASKER CERTIFIED SOLUTION
membership
Create a free account to see this answer
Signing up is free and takes 30 seconds. No credit card required.
ASKER
thxs
https://www.experts-exchange.com/questions/22015257/How-to-create-and-mail-enable-contacts-via-script.html
Hope this helps~!