Microsoft:Exchange:ADSMTPList

From My Notepad
Jump to: navigation, search

Getting a list of all Exchange SMTP contacts

The following script will give you a text file name smtpaddresses.txt with a format appropriate for Postfix relay_recipients.

Make sure you update the LDAP container on line 11 before running the script.

'Global variables
Dim Container
Dim OutPutFile
Dim FileSystem

'Initialize global variables
Set FileSystem = WScript.CreateObject("Scripting.FileSystemObject")
Set OutPutFile = FileSystem.CreateTextFile("smtpaddresses.txt", True)

'Replace with valid DN of the container you want to enumerate
Set Container=GetObject("LDAP://DC=domain,DC=loc")

'Enumerate Container
EnumerateUsers Container

'Clean up
OutPutFile.Close
Set FileSystem = Nothing
Set Container = Nothing

'Say Finished when your done
WScript.Echo "Finished"
WScript.Quit(0)

'List all Users
Sub EnumerateUsers(Cont)
Dim User

'Go through all Users and select them
For Each User In Cont
Select Case LCase(User.Class)

'If you find Users
Case "user"
  'Select all proxyAddresses
  Dim Alias
  If Not IsEmpty(User.proxyAddresses) Then
    'OutPutFile.Write User.DisplayName
    For Each Alias in User.proxyAddresses
  	If InStr(1,Alias,"smtp",1) > 0 Then
			OutPutFile.WriteLine Replace(Alias,"smtp:","",1,1,1) & " OK"
		End If
    'WScript.Echo Alias
  	Next
  End If

Case "organizationalunit" , "container"
  EnumerateUsers User

End Select
Next
End Sub