This is a VBS script for Windows Server 2003 and Exchange 2003 to list all the non-local e-mail addresses in AD. It’s handy if you have a 3rd part spam filter and need to get a list of addresses to let through:
Option Explicit
'Declare our variables
Dim adoLDAPCon, adoLDAPRS, strLDAP, strDomainName, objNetwork
Dim strDN, objUser, colAddr, strAddr
' Grab the domain name
Set objNetwork = CreateObject("Wscript.Network")
strDomainName = objNetwork.UserDomain
' Create an ADO DB connection through ADSI to get a list of users and public folders
Set adoLDAPCon = CreateObject("ADODB.Connection")
adoLDAPCon.Provider = "ADsDSOObject"
adoLDAPCon.Open "ADSI"
strLDAP = "'LDAP://" & strDomainName & "'"
WScript.Echo "Getting mail addresses from " & strLDAP
Set adoLDAPRS = adoLDAPCon.Execute("select ADsPath from " & strLDAP & _
" WHERE objectClass = 'publicFolder' OR objectClass = 'User'")
While Not adoLDAPRS.EOF
strDN = adoLDAPRS.Fields("ADsPath").value
Set objUser = GetObject(strDN)
' Only try to display if the object has "proxyAddresses" set
If Not IsEmpty(objUser.proxyAddresses) Then
colAddr = objUser.GetEx("proxyAddresses")
For Each strAddr in colAddr
strAddr = LCase(strAddr)
If Left(strAddr, 5) = "smtp:" And Right(strAddr, 6) <> ".local" Then _
Wscript.Echo objUser.cn & ": " & Mid(strAddr, 6)
Next
End If
Set objUser = Nothing
adoLDAPRS.MoveNext
Wend
adoLDAPRS.Close
Set adoLDAPRS = Nothing
Set adoLDAPCon = Nothing
You can modify the query strings to get only Public Folders or to get only users. Also, modifying the output format is easy enough.
