Issuu on Google+

Test.txt '===================================================== ' ' VBScript Source File -- Created with SAPIEN Technologies PrimalScript 3.1 ' ' NAME: CreateDL.VBS ' ' AUTHOR: Eric Woodford ' DATE : 7/25/2008 ' ' COMMENT: Script is designed to create fully populated distribution lists. ' The data is pulled from a CSV file. ' Assigned fields are: ' Display Name, ' Alias, ' SMTP Email address, ' Proxy SMTP addresses, ' Accept Messages from, ' Maximum Accepted message size (KB - integer format please) ' Members of the group ' ' Known issue: Accounts with more than 1 proxy address mail fail to load correctly. Still working out the details. ' ProxyAddresses - <a href="http://www.eggheadcafe.com/forumarchives/scriptingVisualBasicscript/Aug2005 /post23622005.asp '===================================================== Const" title="http://www.eggheadcafe.com/forumarchives/scriptingVisualBasicscript/Aug200 5/post23622005.asp '===================================================== Const">http://www.eggheadcafe.com/forumarchives/scriptingVisualBasicscript/Aug2.. .</a> ForReading = 1, ForWriting = 2, ForAppending = 8 Const DLGroupEA3 = "Finance DLs" Const GroupOU = "OU=Test," Const CSVFilePath = "C:\Test.csv" Const LogFIlePath = "C:\CreateDL.LOG" Set fso = CreateObject("scripting.filesystemobject") Set myCSV = fso.opentextfile(CSVFilePath, ForReading) Set MyLogFile = fso.opentextfile(LogFIlePath, ForWriting, True) Do While Not MyCSV.AtEndOfStream strCSVLine = myCSV.Readline If InStr(strCSVLine,"@")>0 Then ' if it contains a SMTPEmail Address, it must be valid (not a header). arrStrUser = Split(strCSVLine,",") strAlias = arrStrUser(1) strDisplayName = arrStrUser(0) strSMTP = arrStrUser(2) strMembers = arrStrUser(3) strAcceptFrom = arrStrUser(4) IntMaxMsgSize = cint(arrStrUser(6)) CreateDistGroup strAlias,strDisplayName, strSMTP ,strAcceptFrom, IntMaxMsgSize End If Loop MyLogFile.Writeline "Adding Users" Set myCSV = fso.opentextfile(CSVFilePath, ForReading) Do While Not MyCSV.AtEndOfStream strCSVLine = myCSV.Readline If InStr(strCSVLine,"@")>0 Then ' if it contains a SMTPEmail Address, it must be valid (not a header). arrStrUser = Split(strCSVLine,",") strAlias = arrStrUser(1) strMembers = arrStrUser(3) Page 1


Test.txt AddGroupMembers strAlias, strMembers End If loop MyLogFile.close MyCSV.Close Sub CreateDistGroup(strAlias, strDisplayname, strSMTP, intMaxSizeKB ) Dim strGroup, strDNSDomain Dim objOU, objGroup, objUser

strAcceptMsgsFrom,

Const ADS_GROUP_TYPE_UNIVERSAL_GROUP = &h8 Const ADS_GROUP_TYPE_SECURITY_ENABLED = &h80000000 Const ADS_GROUP_TYPE_GLOBAL_GROUP = &h2 Const Const Const Const

ADS_PROPERTY_CLEAR = 1 ADS_PROPERTY_UPDATE = 2 ADS_PROPERTY_APPEND = 3 ADS_PROPERTY_DELETE = 4

Set objRootDSE = GetObject("LDAP://RootDSE") strDNSDomain = objRootDSE.Get("DefaultNamingContext") Set objOU = GetObject("LDAP://" & GroupOU & strDNSDomain ) strNewGpLong = "CN=" & strAlias Err.Clear On Error Resume Next Set testGroup = GetObject ("LDAP://"&strNewGpLong&","& GroupOU & strDNSDomain) If Err <> 0 Then MyLogFile.Writeline "creating: " & strDisplayname &"("&strAlias&")" Set objGroup = objOU.Create("Group",strNewGpLong) objGroup.Put "sAMAccountName", strAlias Else MyLogFile.Writeline strDisplayname & " already exists" End If objGroup.put "Name", Replace(StrDisplayName," ","") objGroup.Put "displayname", strDisplayname objGroup.Put "groupType", ADS_GROUP_TYPE_GLOBAL_GROUP objGroup.put "extensionAttribute3", DLGroupEA3 if intMaxSizeKB > 0 then objGroup.put "delivcontlength", intMaxSizeKB objGroup.mailenable objGroup.setInfo objGroup.put "dLMemSubmitPerms", "cn="&strAcceptMsgsFrom&","&GroupOU & strDNSDomain if instr(strSMTP,";")=0 Then strNewSMTP = mid(strSMTP,6) 'strNewSMTP = strSMTP MyLogFile.Writeline "Adding : " & strNewSMTP objGroup.Put "mail", strNewSMTP objGroup.put "targetAddress", strNewSMTP objGroup.PutEx ADS_PROPERTY_UPDATE, "ProxyAddresses", array(strSMTP) objGroup.SetInfo Else arrSMTP= Split(StrSMTP,";") strNewSMTP = mid(arrSMTP(0),6) MyLogFile.Writeline "Adding : " & strNewSMTP objGroup.Put "mail", strNewSMTP 'http://support.microsoft.com/kb/q260251/ x = 0 For Each sAddress In arrSMTP MyLogFile.Writeline "+" & sAddress If x = 0 Then objGroup.PutEx ADS_PROPERTY_UPDATE, Page 2


Test.txt "ProxyAddresses", array(sAddress) objGroup.put "targetAddress", sAddress x = x + 1 Else objGroup.PutEx ADS_PROPERTY_APPEND, "ProxyAddresses", array(sAddress) End if objGroup.SetInfo Next End If objGroup.setInfo Set objGroup = Nothing End Sub Sub AddGroupMembers (strAlias, strMembers) On Error Resume next Set objRootDSE = GetObject("LDAP://RootDSE") strDNSDomain = objRootDSE.Get("DefaultNamingContext") Set objGroup = GetObject ("LDAP://cn="&strAlias&","& GroupOU & strDNSDomain) If strMembers <> "" Then arrMembers = Split(strMembers,";") For Each struser In arrMembers Err.Clear objGroup.Add("LDAP://cn="&strUser&","&GroupOU & strDNSDomain) If Err = 0 Then MyLogFile.Writeline "Successfully added: " & strUser & " -> " & strAlias Else MyLogFile.Writeline "Failed : " & strUser & " -> " & strAlias End If next End if End Sub

Page 3


test