• Creator
  • #2242425

    Exchange 2003 and Printing In-use Email Addresses


    by ageranger10 ·

    I’m looking for a way to obtain a listing of the email addresses in use on my Exchange 2003 server. I’d like to export the info to a text file as a way to document the Exchange server configuration. I have about 65 mailboxes, most of which have 2 or 3 aliases. Some of which have many aliases. Any help would be greatly appreciated.

All Answers

  • Author
    • #2666602


      by ageranger10 ·

      In reply to Exchange 2003 and Printing In-use Email Addresses


    • #2775083

      I found this…

      by cokeonice ·

      In reply to Exchange 2003 and Printing In-use Email Addresses

      …and it works great!

      Change the OU on line 7 to your OU and run for each OU that contains users.

      This redirects the output to a csv file.
      Run the script like this:

      cscript email.vbs > email.csv

      Option Explicit

      Dim objRootDSE, strDNSDomain, objCommand, objConnection
      Dim strBase, strFilter, strAttributes, strQuery, objRecordSet
      Dim strNTName, strDN, colmail, strmail, stremail, strOU

      StrOU = “OU=YourOU,”

      ‘ Determine DNS domain name.
      Set objRootDSE = GetObject(“LDAP://RootDSE”)
      strDNSDomain = objRootDSE.Get(“defaultNamingContext”)

      ‘ Use ADO to search Active Directory.
      Set objCommand = CreateObject(“ADODB.Command”)
      Set objConnection = CreateObject(“ADODB.Connection”)
      objConnection.Provider = “ADsDSOObject”
      objConnection.Open “Active Directory Provider”
      objCommand.ActiveConnection = objConnection

      ‘ Search entire domain.
      strBase = “

      ‘ Filter on contacts
      strFilter = “(&(&(& (mailnickname=*)(| (&(objectCategory=person)(objectClass=user))))))”

      ‘ Comma delimited list of attribute values to retrieve.
      strAttributes = “cn,distinguishedName,adspath,proxyaddresses”

      ‘ Construct the ADO query, using LDAP syntax.
      strQuery = strBase & “;” & strFilter & “;” & strAttributes & “;subtree”

      ‘ Run the query.
      objCommand.CommandText = strQuery
      objCommand.Properties(“Page Size”) = 100
      objCommand.Properties(“Timeout”) = 30
      objCommand.Properties(“Cache Results”) = False
      Set objRecordSet = objCommand.Execute

      ‘ Enumerate the recordset and output the values retrieved in
      ‘ comma delimited format.
      Do Until objRecordSet.EOF
      strNTName = objRecordSet.Fields(“cn”).Value
      strDN = objRecordSet.Fields(“distinguishedName”).Value
      colmail = objRecordSet.Fields(“proxyAddresses”)

      If IsEmpty(colMail) Then
      ‘ The attribute is empty (has no values).
      wscript.echo “No Email address”
      ‘ The attribute has one or more values – enumerate.
      For Each strMail In colMail
      If Instr(strMail, “SMTP:”) then
      strEmail = Right(strMail, Len(strMail)-5)
      End If
      End If
      Wscript.Echo strNTName & “,” & strEmail

      ‘ Clean up.
      Set objRootDSE = Nothing
      Set objCommand = Nothing
      Set objConnection = Nothing
      Set objRecordSet = Nothing

      • #2754411


        by ageranger10 ·

        In reply to I found this…

        I’ll try it tomorrow

      • #2752642

        Didn’t run for me

        by ageranger10 ·

        In reply to I found this…

        I changed the OU in line 7 and the domain in line 21, Errored out on line 37,1. But that’s an empty line, so I assume the error in on line 36. Any idea what’s wrong?

Viewing 1 reply thread