Solved

Extract All SMTP Addresses in Domain

Posted on 2004-08-04
5
3,748 Views
Last Modified: 2008-01-09
need to extract all SMTP addresses in a Win 2k3 AD domain.  i can use CSVD edit to extract proxy addresses but the resulting format is not easy to export to a text file..  i need a way to export IDs in one colume of a an Excel, not the way this command does it:
          csvde -f ProxyAddressExport.csv -r (objectClass=user) -l proxyAddresses
 
please, i am only looking for answers that include all proxy/smtp addresses in one column.  it has to be done through native Windows tools, no 3rd party products.  


disclaimer:
i will not award points to memebers that do not fully give the answer.
stating "it cannot be done" is not an answer and you will not be awarded credit.
0
Comment
Question by:xxgenius
  • 2
  • 2
5 Comments
 
LVL 21

Expert Comment

by:marc_nivens
ID: 11719475
I wrote a script a while back to do just this.  Copy the script below, paste it into notepad, and save as a .vbs.  When you launch it, it asks you for servername domain.  If you server is named DC1, and your domain was test.com, you would enter:  DC1/dc=test,dc=com

This will dump all users in the domain to an ldif formatted file that contains their proxy addresses.  You can use this ldif file to reimport later on if needed.





Const Writable       = 2

Set objFSO             = CreateObject("Scripting.FileSystemObject")
Set objLog            = objFSO.OpenTextFile("c:\proxydump.ldf", Writable, True)
Set cn                 = CreateObject("ADODB.Connection")
Set cm                  = CreateObject("ADODB.Command")
Set rs                  = CreateObject("ADODB.RecordSet")


With cn
      .Provider      = "ADsDSOObject"
      .Open "Active Directory Provider"
End With

Set cm.ActiveConnection = cn

strDomainDN            = InputBox("Please Enter the Servername and Domain DN. " & vbCrLf & " Example: Myserver/DC=test,DC=lab ")

cm.CommandText = "<LDAP://" & strDomainDN & ">;(&(objectCategory=user)(proxyAddresses=*));distinguishedName,mail,proxyAddresses;subtree"
cm.Properties("Page Size") = 1000

Set rs                  = cm.Execute


While Not rs.EOF

      On Error Resume Next
      strUserDN      = rs.Fields("distinguishedName")
      strMail            = rs.Fields("mail")
      strProxyAddress = rs.Fields("proxyAddresses")

      objLog.Write "dn: " & strUserDN & vbCrLf
      objLog.Write "changetype: modify" & vbCrLf
      objLog.Write "replace: mail" & vbCrLf
      objLog.Write "mail: " & strMail & vbCrLf
      objLog.Write "-" & vbCrLf & vbCrLf

      objLog.Write "dn: " & strUserDN & vbCrLf
      objLog.Write "changetype: modify" & vbCrLf
      objLog.Write "replace: proxyAddresses" & vbCrLf

      For Each Item in strProxyAddress
            strTempAddr = Item
            objLog.Write "proxyAddresses: " & Item & vbCrLf
      Next

      objLog.Write "-" & vbCrLf & vbCrLf

      rs.MoveNext
Wend
                  

objLog.Close
msgbox "Export Complete to c:\proxydump.ldf"
0
 
LVL 21

Accepted Solution

by:
marc_nivens earned 500 total points
ID: 11719552
I just noticed that you have a specific way you want the output formatted.  You can modify the above script to do this.  Use the script below if you want it outputted to CSV, user DN in 1st column and proxy addresses in second column (separated by semicolon):




Const Writable      = 2

Set objFSO           = CreateObject("Scripting.FileSystemObject")
Set objLog          = objFSO.OpenTextFile("c:\proxydump.csv", Writable, True)
Set cn               = CreateObject("ADODB.Connection")
Set cm               = CreateObject("ADODB.Command")
Set rs               = CreateObject("ADODB.RecordSet")


With cn
     .Provider     = "ADsDSOObject"
     .Open "Active Directory Provider"
End With

Set cm.ActiveConnection = cn

strDomainDN          = InputBox("Please Enter the Servername and Domain DN. " & vbCrLf & " Example: Myserver/DC=test,DC=lab ")

cm.CommandText = "<LDAP://" & strDomainDN & ">;(&(objectCategory=user)(proxyAddresses=*));distinguishedName,mail,proxyAddresses;subtree"
cm.Properties("Page Size") = 1000

Set rs               = cm.Execute


While Not rs.EOF

     On Error Resume Next
     strUserDN     = rs.Fields("distinguishedName")
     strProxyAddress = rs.Fields("proxyAddresses")

     objLog.Write strUserDN
     objLog.Write ","
 
     For Each Item in strProxyAddress
          strTempAddr = Item
          objLog.Write Item & ";"
     Next

     objLog.Write vbCrLf

     rs.MoveNext
Wend
               

objLog.Close
msgbox "Export Complete to c:\proxydump.csv"
0
 
LVL 8

Author Comment

by:xxgenius
ID: 11719560
thanks, but i will not be able to use a third party too or VB script for security purposes.
0
 
LVL 8

Author Comment

by:xxgenius
ID: 11719621
even though i can't use it for this client, i'm sure i'll be able to use it in the future. thanks.  for this project i'm using some nifty find and replace tricks that worked in a few minutes.
0
 
LVL 17

Expert Comment

by:Microtech
ID: 11719707
that is what i was looking for too thanks ^_^
0

Featured Post

Highfive + Dolby Voice = No More Audio Complaints!

Poor audio quality is one of the top reasons people don’t use video conferencing. Get the crispest, clearest audio powered by Dolby Voice in every meeting. Highfive and Dolby Voice deliver the best video conferencing and audio experience for every meeting and every room.

Join & Write a Comment

Easy CSR creation in Exchange 2007,2010 and 2013
Marketers need statistics and metrics like everybody else needs oxygen. In this article we explain how to enable marketing campaign statistics for Microsoft Exchange mail.
In this video we show how to create a Distribution Group in Exchange 2013. We show this process by using the Exchange Admin Center. Log into Exchange Admin Center.: First we need to log into the Exchange Admin Center. Navigate to the Recipients >>…
In this video we show how to create a Shared Mailbox in Exchange 2013. We show this process by using the Exchange Admin Center. Log into Exchange Admin Center.: First we need to log into the Exchange Admin Center. Navigate to the Recipients >> Sha…

707 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

12 Experts available now in Live!

Get 1:1 Help Now