1. CVS 파일을 만든다.
[형식]
primarysmtp@domain1.com (원래 메일 주소), proxyaddress@domain2.com (추가 메일 주소)
2. 다음 스크립트를 실행한다.
Option Explicit
Const CSV_FILE = "file.txt"
Const FILE_DELIMITER = ", "
Const ADS_SCOPE_SUBTREE = 2
Dim objFileSystem, objFile, objStream, objUsers, objConnection, objCommand, objRootDSE, objRecordSet, objUser
Dim strPrimarySMTP, strNewSMTP, strAddresses
Dim arrLine, arrAddresses
Set objFileSystem = CreateObject("Scripting.FileSystemObject")
Set objFile = objFileSystem.GetFile(CSV_FILE)
Set objStream = objFile.OpenAsTextStream(1, 0)
Set objUsers = CreateObject("Scripting.Dictionary")
Do While Not objStream.AtEndOfStream
arrLine = Split(objStream.ReadLine, FILE_DELIMITER)
If UBound(arrLine) = 1 Then
strPrimarySMTP = LCase(arrLine(0))
strNewSMTP = LCase(arrLine(1))
If Not objUsers.Exists(strPrimarySMTP) Then
objUsers.Add strPrimarySMTP, strNewSMTP
End If
End If
Loop
Set objStream = Nothing
Set objFile = Nothing
Set objConnection = CreateObject("ADODB.Connection")
objConnection.Provider = "ADsDSOObject"
objConnection.Open "Active Directory Provider"
Set objCommand = CreateObject("ADODB.Command")
objCommand.ActiveConnection = objConnection
Set objRootDSE = GetObject("LDAP://RootDSE")
objCommand.CommandText = "SELECT aDSPath, mail " &_
"FROM 'LDAP://" & objRootDSE.Get("defaultNamingContext") & "' WHERE objectClass='user'"
Set objRootDSE = Nothing
objCommand.Properties("Page Size") = 1000
objCommand.Properties("Timeout") = 600
objCommand.Properties("Searchscope") = ADS_SCOPE_SUBTREE
objCommand.Properties("Cache Results") = False
Set objRecordSet = objCommand.Execute
Set objFile = objFileSystem.OpenTextFile("logfile.txt", 2, True, 0)
While Not objRecordSet.EOF
If Not IsNull(objRecordSet.Fields("mail")) Then
strPrimarySMTP = LCase(objRecordSet.Fields("mail"))
If objUsers.Exists(strPrimarySMTP) Then
Set objUser = GetObject(objRecordSet.Fields("aDSPath"))
arrAddresses = objUser.Get("proxyAddresses")
' Check the Address isn't already there
strAddresses = Join(arrAddresses, ",")
If InStr(1, strAddresses, ",smtp:" & objUsers(strPrimarySMTP) & ",", VbTextCompare) = 0 Then
ReDim Preserve arrAddresses(UBound(arrAddresses) + 1)
arrAddresses(UBound(arrAddresses)) = "smtp:" & objUsers(strPrimarySMTP)
objFile.WriteLine strPrimarySMTP & ": Matched to " & objUser.Get("name") &_
": " & objUsers(strPrimarySMTP) & " Address Added"
' objUser.Put "proxyAddresses", arrAddresses
' objUser.SetInfo
Else
objFile.WriteLine strPrimarySMTP & ": Matched to " & objUser.Get("name") &_
": " & objUsers(strPrimarySMTP) & " Address Exists"
End If
Set objUser = Nothing
End If
End If
objRecordSet.MoveNext
Wend
objConnection.Close
Set objFile = Nothing
Set objFileSystem = Nothing
Set objRecordSet = Nothing
Set objCommand = Nothing
Set objConnection = Nothing
Set objUsers = Nothing
출처 :
http://www.experts-exchange.com/Software/Server_Software/Email_Servers/Exchange/Q_22090180.html
참고 :
원치 않는 프록시 주소 삭제 : http://support.microsoft.com/kb/318774