如果用户有多个SMTP地址,有的时候我们需要导出到一个表内,那么使用下面的脚本就可以轻松的导出除了SIP和X400地址用户所有的Proxyaddress。如果需要SIP相关的Proxyaddress,那么简单的把相关的IF判断语句删除就OK了。导出的用户的格式为:用户名 <TAB>第一个SMTP地址<TAB>第二个SMTP地址,由于数据之间采用TAB隔开,所以可以方便的导入到Excel内。

Const ForWriting = 2
Const strX400Search = "X400"

'Path for the output file
filePath = "d:\AllSMTPProxies.txt"

'Setup output file
Set objFSO = CreateObject("Scripting.FileSystemObject")
Set objTextFile = objFSO.OpenTextFile(filepath, ForWriting, True)

'Create Objects for LDAP Queries
Set rootDSE = GetObject("LDAP://RootDSE")
DomainContainer = rootDSE.Get("defaultNamingContext")

Set conn = CreateObject("ADODB.Connection")
conn.Provider = "ADSDSOObject"
conn.Open "ADs Provider"

'LDAP query for all mail users
strLDAP = "<LDAP://" & DomainContainer & ">;(&(mailnickname=*)(objectCategory=person)(objectClass=user));adspath;subtree"

'Get query results and output to file
Set oComm = CreateObject("ADODB.Command")
oComm.ActiveConnection = conn
oComm.CommandText = strLDAP
oComm.Properties("Sort on") = "DisplayName"
oComm.Properties("Page size") = 1500

Set rs = oComm.Execute

While Not rs.EOF
    
Set FoundObject = GetObject (rs.Fields(0).Value)
   
arrProxyAddresses = FoundObject.proxyAddresses

If IsArray(FoundObject.proxyAddresses) Then

add=""
For Each Address In arrProxyAddresses
    If InStr(Address, strX400Search) <> 0  Then
        'wscript.echo "X400 Address"
        else
            If left(Address,4)= "SIP:" or left(Address,4)= "sip:"  Then
            else
                add=add&address&vbTab
            End if
        End if
Next
objTextFile.writeLine(FoundObject.Displayname & vbTab & add)
else
objTextFile.writeLine(FoundObject.Displayname & vbTab & arrProxyAddresses)
end if


rs.MoveNext

Wend

MsgBox "Processing complete!"