Extract All SMTP Addresses in Domain

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.
LVL 8
xxgeniusAsked:
Who is Participating?
 
marc_nivensConnect With a Mentor Commented:
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
 
marc_nivensCommented:
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
 
xxgeniusAuthor Commented:
thanks, but i will not be able to use a third party too or VB script for security purposes.
0
 
xxgeniusAuthor Commented:
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
 
MicrotechCommented:
that is what i was looking for too thanks ^_^
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.