Announcement

Collapse
No announcement yet.

How can I find or list ALL email adresses

Collapse
This topic is closed.
X
X
  • Filter
  • Time
  • Show
Clear All
new posts

  • How can I find or list ALL email adresses

    in Active Directory?

    I'm running Windows 2003 native and Exhange 2007.

    I have searched the forums and all over the internet and
    no luck in finding a answer.

    Please help me.

    Regards, Sebastian

  • #2
    Re: How can I find or list ALL email adresses

    well, you could create a qbd and include all users with an inbox...

    this will create a disto list that you can export to a text file.

    or check out this thread. you should be able to piece together a query to generate a list without having to create a qbd.

    http://forums.petri.com/showthread.php?t=7690


    hope that helps!
    its easier to beg forgiveness than ask permission.
    Give karma where karma is due...

    Comment


    • #3
      Re: How can I find or list ALL email adresses

      I think I have to re-phrase myself...

      I know how to make a distribution group or a dynamic such, I also know
      how to put all users, groups etc which has got an email address in that group.

      So:
      I want to list ALL email addresses in the AD.
      Not just the primary address or all items that has an email address.

      for example:
      The IT department @ Microsoft might have
      [email protected], [email protected], [email protected] etc.

      I can see all those addresses on the email tab on the group object "IT Department".

      Of cource I can check the email tab on all objects to find that info...
      But I want to get a list.

      And using queries just gives me a list of objects, not the properties of the email tab,

      So anyone know?

      Comment


      • #4
        Re: How can I find or list ALL email adresses

        Define a custom query in Active Directory Users and Computers. the query string should be proxyAddresses=smtp:*@yourdomain
        Attached Files
        Last edited by netxt; 22nd August 2007, 14:29.
        Regards,
        Csaba Papp
        MCSA+messaging, MCSE, CCNA
        ...............................
        Remember to give credit where credit is due and leave reputation points where appropriate
        .................................

        Comment


        • #5
          Re: How can I find or list ALL email adresses

          Thanx! (almost)
          It seems as a perfect answer...

          After doing that, what shall I do?
          There is no "execute" or "run" query on the right-click menu.
          Neither does a double-click help.....

          Am I a retard or what?

          Comment


          • #6
            Re: How can I find or list ALL email adresses

            OK, it did work on the Exchange server AD Users & Computers, not on the DC.

            But, back on status quo.

            It does not show the proxy adresses, only name, type and description.

            That query searches for proxyadresses which matches the query and
            shows the object that contains the proxyaddress.

            And that is exactly what I didn't want.

            There is lots of ways to get the names of the objects.
            But still no list of the proxy addresses.

            Anyone?

            Comment


            • #7
              Re: How can I find or list ALL email adresses

              In 'Saved Query' rightclick on the query and choose 'Refresh'. (If the rightpane stays empty then the result = empty).

              The Ldap query string
              proxyAddresses=smtp:*@yourmaildomain.com
              Will select all objects which have emailaddresses stored in the Active Directory included Users, Groups, Contacts and Public Folders. But it will not filter-out X400 addresses and other domains from these object!, since all proxyaddresses are stored in one and the same array.

              Via menu View / Add/Remove columns you can add the column emailaddres. But that wil only show just one (the primary-) emailaddress in the query results.

              I think the only option here is using a script.
              With a vbscript (in comparing to DSQuery.exe) you do can select the attributes you like to show.

              Code:
              ' name:   ListAllEmailaddresses.vbs
              ' author: Remco Simons [nl] 2007
              
              ' ( http://forums.petri.com/showthread.php?t=17911 )
              '=======================================================================
              
              
              Const strX400Search          = "X400:"
              Const Primary_EmailAddress   = "SMTP:"
              Const Secondary_EmailAddress = "smtp:"
              
              strOutputFile = "C:\proxyaddresses.csv"
              
              Set objRootDSE = GetObject("LDAP://rootDSE")
              strDNSDomain = objRootDSE.Get("defaultNamingContext")
              
              'Set the ADO connection query strings
              QueryPath ="" & strDNSDomain
              strFilter = "(&(proxyAddresses=*))"
              strAttributes = "adspath"
              
              'Start the ADO connection
              Set objCommand = CreateObject("ADODB.Command")
              Set objConnection = CreateObject("ADODB.Connection")
              objConnection.Provider = "ADsDSOObject"
              objConnection.Open "Active Directory Provider"
              objCommand.ActiveConnection = objConnection
              
              'Create the Query
              strQuery = "<LDAP://" & QueryPath & ">;" & strFilter & ";" _
                          & strAttributes & ";subtree"
              
              objCommand.CommandText = strQuery
              objCommand.Properties("Page Size") = 1000
              objCommand.Properties("Timeout") = 30
              objCommand.Properties("Cache Results") = False
              
              Set objRecordSet = objCommand.Execute
              
              objCount = 0
              'objCount = objRecordSet.RecordCount '<--not possible when 'caching results' is false
              addrCount = 0
              
              If not objRecordSet.eof then 
                objRecordSet.MoveFirst
              
                'Get the emailaddresses of all Items with a proxyaddress in the domain
                While Not objRecordset.EOF
                  objCount = objCount + 1
                  strItemPath = objRecordSet.Fields("AdsPath").Value
                  Set objItem = GetObject(strItemPath)
                  strObjClass = objItem.class
                  ProxyAddresses = objItem.proxyAddresses
              
                  If IsArray(ProxyAddresses) Then
                      For Each ProxyAddress in ProxyAddresses
                         If Not CBool(InStr(UCase(ProxyAddress), strX400Search)) Then
                            emailaddres = "present"
                            addrCount = addrCount + 1
                            If CBool(InStr(ProxyAddress, Primary_EmailAddress)) Then _
                               emailaddres = Mid(proxyAddress,6) & ",Primary"
                            If CBool(InStr(ProxyAddress, Secondary_EmailAddress)) Then _
                               emailaddres = Mid(proxyAddress,6) & ",Secondary"
                            strResult = strResult & VbCrlf & strObjClass & "," & _
                                   chr(34) & objItem.distinguishedName & chr(34) _
                                   & "," & emailaddres
                         End If
                      Next
                  Else
                      ProxyAddress = ProxyAddresses
                         If Not CBool(InStr(UCase(ProxyAddress), strX400Search)) Then
                            emailaddres = "present"
                            addrCount = addrCount + 1
                            If CBool(InStr(ProxyAddress, Primary_EmailAddress)) Then _
                               emailaddres = Mid(proxyAddress,6) & ",Primary"
                            If CBool(InStr(ProxyAddress, Secondary_EmailAddress)) Then _
                               emailaddres = Mid(proxyAddress,6) & ",Secondary"
                            strResult = strResult & VbCrlf & strObjClass & "," & _
                                   chr(34) & objItem.distinguishedName & chr(34) _ 
                                   & "," & emailaddres & ",#"
                         End If
                  End If
              
                  objRecordSet.MoveNext
                Wend
              End If
              objRecordSet.Close
              
              'Output to a text file
              Set objFileSystem = CreateObject("Scripting.FileSystemObject")
              Set objOutputFile = objFileSystem.CreateTextFile(strOutputFile)
               objOutputFile.Write "objectClass,DistinguishedName,Emailaddress,pri/sec address,'"
               objOutputFile.Write strResult
               objOutputFile.close
              
              wscript.echo "Counted: ", objCount, "records and", addrCount, "emailaddresses"
              
              Wscript.quit
              The output file is a csv-file. In Excel you can sort the results
              by: class, dn, pri/sec
              or by: emailaddress


              \Rems
              Last edited by Rems; 25th October 2007, 19:44. Reason: typos

              This posting is provided "AS IS" with no warranties, and confers no rights.

              __________________

              ** Remember to give credit where credit's due **
              and leave Reputation Points for meaningful posts

              Comment


              • #8
                Re: How can I find or list ALL email adresses

                the saved query is available on windows 2003. the email address tab should be added from the View -> Add / Removes Columns
                Attached Files
                Regards,
                Csaba Papp
                MCSA+messaging, MCSE, CCNA
                ...............................
                Remember to give credit where credit is due and leave reputation points where appropriate
                .................................

                Comment


                • #9
                  Re: How can I find or list ALL email adresses

                  Originally posted by netxt View Post
                  the saved query is available on windows 2003. the email address tab should be added from the View -> Add / Removes Columns
                  It does not show the proxy adresses, only name, type and description
                  AND primary smtp address.

                  thanx anyway.

                  I will try REMS tip in a couple of hours.

                  But I still think that the built-in search capabilities should be able to acctually
                  show what you are searching for, which is doesn't.

                  I hope that Windows Server 2008 will solve that.

                  Comment


                  • #10
                    Re: How can I find or list ALL email adresses

                    Thanx REMS!

                    ListAllEmailaddresses.vbs did work.

                    So the case is solved.
                    But if someone know some gui that can do the same, please let me know.

                    I stated working with firewalls, Exchange, Windows Server etc for 12 years ago
                    an have actively decided NOT to learn any programming languages.
                    That should be for developers. I want tools to do admin stuff.

                    So guess if I'm happy with the Power Shell.....
                    (I want it, but only as a complement, I mean changing mailbox permissions ONLY in PS???)

                    The GUI is one of Microsoft's Windows applications biggest advantages over lunux/unix. WHY change ???

                    Thanx again for your help.

                    Comment


                    • #11
                      Re: How can I find or list ALL email addresses

                      So the case is solved.
                      Glad I could help.


                      \Rems


                      btw
                      Here is the same script but in this version I added an extra column with just the EmailDomain for better sorting in excel.
                      Code:
                      ' ======================================================================
                      '| name  :  ListAllEmailaddresses.vbs
                      '| author:  Remco Simons [nl] 2007
                      '|
                      '| version 2c 
                      '|    in version 2 I added an extra column "MailDomain"
                      '|       -that can be used icw/ AutoFiltering in Excel-
                      '|
                      '| ( http://forums.petri.com/showthread.php?t=17911 )
                      ' ======================================================================
                      Option Explicit
                      
                      Const X400_ENTRY             = "X400:"
                      Const PRIMARY_EMAILADDRESS   = "SMTP:"
                      Const SECONDARY_EMAILADDRESS = "smtp:"
                      
                      Dim ProxyAddress, strResult, addressCount
                      Dim recordCount
                      Dim strOutputFile, objRootDSE, strDNSDomain, QueryPath, strFilter
                      Dim strAttributes, objCommand, objConnection, strQuery, objRecordSet
                      Dim strItemPath, objItem, ProxyAddresses, objFileSystem, objOutputFile
                      
                      strOutputFile = "C:\proxyaddresses.csv"
                      
                      Set objRootDSE = GetObject("LDAP://rootDSE")
                      strDNSDomain = objRootDSE.Get("defaultNamingContext")
                      
                      'Set the ADO connection query strings
                      QueryPath = "" & strDNSDomain
                      strFilter = "(proxyAddresses=*)"
                      strAttributes = "adspath"
                      
                      'Start the ADO connection
                      Set objCommand = CreateObject("ADODB.Command")
                      Set objConnection = CreateObject("ADODB.Connection")
                      objConnection.Provider = "ADsDSOObject"
                      objConnection.Open "Active Directory Provider"
                      objCommand.ActiveConnection = objConnection
                      
                      'Create the Query
                      strQuery = "<LDAP://" & QueryPath & ">;" & strFilter & ";" _
                                  & strAttributes & ";subtree"
                      
                      objCommand.CommandText = strQuery
                      objCommand.Properties("Page Size") = 1000  'min=1 and max=1000 ! <buffering#>
                      objCommand.Properties("Timeout") = 30  'in seconds
                      objCommand.Properties("Cache Results") = False  'read only once
                      
                      Set objRecordSet = objCommand.Execute
                      
                      recordCount = 0
                      'recordCount = objRecordSet.RecordCount '<--not possible when 'caching results' is false
                      addressCount = 0
                      
                      If not objRecordSet.eof then 
                        objRecordSet.MoveFirst
                      
                        'Get the emailaddresses of all Items with a proxyaddress in the domain
                        While Not objRecordset.EOF
                          recordCount = recordCount + 1
                          strItemPath = objRecordSet.Fields("AdsPath").Value
                          Set objItem = GetObject(strItemPath)
                          If Not IsEmpty(objItem.proxyAddresses) then
                            For Each ProxyAddress in objItem.GetEx("proxyAddresses")
                               call SearchSMTP(objItem, ProxyAddress)
                            Next
                          End If
                          Set objItem = Nothing
                          objRecordSet.MoveNext
                        Wend
                      End If
                      
                      'Output to a text file
                      Set objFileSystem = CreateObject("Scripting.FileSystemObject")
                      Set objOutputFile = objFileSystem.CreateTextFile(strOutputFile)
                       objOutputFile.Write "MailDomain,objectClass,DistinguishedName,Emailaddress,pri/sec address"
                       objOutputFile.Write strResult
                      
                      'release
                      objOutputFile.close
                      objRecordSet.Close
                      objConnection.Close
                      
                      wscript.echo "Counted: ", recordCount, "records and", addressCount, "emailaddresses"
                      
                      Wscript.quit
                      
                      
                      Sub SearchSMTP(ByVal objItem, ByVal ProxyAddress)
                          If Not CBool(InStr(UCase(ProxyAddress), X400_ENTRY)) Then
                             Dim strObjClass : strObjClass = objItem.class
                             Dim emailaddres : emailaddres = "present"
                             Dim strEmaildomain, arrEmaildomain, i, strRevMailDomain
                      
                             ' You can choose to use strEmaildomain -OR- strRevMailDomain in the ouput (see strResult)
                             strEmaildomain = split(proxyAddress,"@")(1)
                                arrEmaildomain = split(strEmaildomain,".")
                                For i = 0 To UBound(arrEmaildomain)
                                  strRevMailDomain = arrEmaildomain(i) & "." & strRevMailDomain
                                Next
                             strRevMailDomain = LCase(Left("." & strRevMailDomain, _
                                                Len(strRevMailDomain)))
                      
                             addressCount = addressCount + 1
                             If CBool(InStr(ProxyAddress, PRIMARY_EMAILADDRESS)) Then _
                                emailaddres = Mid(proxyAddress,6) & ",Primary"
                             If CBool(InStr(ProxyAddress, SECONDARY_EMAILADDRESS)) Then _
                                emailaddres = Mid(proxyAddress,6) & ",Secondary"
                      
                             strResult = strResult & VbCrlf & _
                                    strRevMailDomain & "," _
                                    & strObjClass & "," _
                                    & chr(34) & objItem.distinguishedName & chr(34) _
                                    & "," & emailaddres
                          End If
                      End Sub
                      Last edited by Rems; 20th November 2007, 14:59. Reason: optimized the script a little bit

                      This posting is provided "AS IS" with no warranties, and confers no rights.

                      __________________

                      ** Remember to give credit where credit's due **
                      and leave Reputation Points for meaningful posts

                      Comment


                      • #12
                        Re: How can I find or list ALL email adresses

                        great script.
                        Is it possible not to include Public folders emails ? (i need only users and ad groups mails list|)

                        Comment


                        • #13
                          Re: How can I find or list ALL email adresses

                          Edit the LDAP filter:
                          Code:
                          strFilter = "(&(|(&(objectCategory=person)(objectClass=user))(objectcategory=group))(proxyAddresses=*))"
                          http://www.petri.com/ldap_search_sam...d_exchange.htm

                          \Rems

                          This posting is provided "AS IS" with no warranties, and confers no rights.

                          __________________

                          ** Remember to give credit where credit's due **
                          and leave Reputation Points for meaningful posts

                          Comment


                          • #14
                            Re: How can I find or list ALL email adresses

                            thank you Rems for the code line.

                            I have a last correction the make :

                            - I want also the display name
                            - I don't want to see in the output file the disable users/groups
                            - When I start the script, I receive a "Window Script Host" window message that shows "counted: x records and y emailaddresses". I don't want to get this window message.

                            Can you help me to correct the script ?
                            Thank you very much.

                            Comment


                            • #15
                              Re: How can I find or list ALL email adresses

                              The scope of the original script was to find ALL the emailaddresses in a AD domain. The script is written with that in mind, and tested for it. And it is as it is.
                              What you called "corrections" can also disturb routines and tunings that are created in a script. It can save a lot of time just to begin writing from scratch again and adapt your whishes in a much better way.

                              Anyway, here are the adjustments, ( i did not test them!)
                              I want also the display name;
                              Code:
                                    strResult = strResult & VbCrlf & _
                                            strRevMailDomain & "," _
                                            & strObjClass & "," _
                                            & objItem.displayName & "," _
                                            & chr(34) & objItem.distinguishedName & chr(34) _
                                            & "," & emailaddres
                              Code:
                              objOutputFile.Write "MailDomain,objectClass,DisplayName,DistinguishedName,Emailaddress,pri/sec address"
                               objOutputFile.Write strResult

                              I don't want to see in the output file the disable users;
                              Code:
                               'Get the emailaddresses of all Items with a proxyaddress in the domain
                                While Not objRecordset.EOF
                                  recordCount = recordCount + 1
                                  strItemPath = objRecordSet.Fields("AdsPath").Value
                                  Set objItem = GetObject(strItemPath)
                                  
                                  DIM AccountDisabled : AccountDisabled=False 
                                  If UCase(objItem.class) = "USER" Then
                                    If objItem.AccountDisabled=True Then AccountDisabled=True
                                  End IF
                              
                                  If Not IsEmpty(objItem.proxyAddresses) And Not AccountDisabled Then
                                    For Each ProxyAddress in objItem.GetEx("proxyAddresses")
                                       call SearchSMTP(objItem, ProxyAddress)
                                    Next
                                  End If
                                  Set objItem = Nothing
                                  objRecordSet.MoveNext
                                Wend
                              End If

                              When I start the script, I receive a "Window Script Host" window message that shows "counted: x records and y emailaddresses". I don't want to get this window message;
                              Code:
                              ' ' wscript.echo "Counted: ", recordCount, "records and", addressCount, "emailaddresses"

                              \Rems
                              Last edited by Rems; 21st November 2007, 11:12. Reason: FIXED! 'disbled users' excluded from the output

                              This posting is provided "AS IS" with no warranties, and confers no rights.

                              __________________

                              ** Remember to give credit where credit's due **
                              and leave Reputation Points for meaningful posts

                              Comment

                              Working...
                              X