Solved

Extract All SMTP Addresses in Domain

Posted on 2004-08-04
5
3,775 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

PRTG Network Monitor: Intuitive Network Monitoring

Network Monitoring is essential to ensure that computer systems and network devices are running. Use PRTG to monitor LANs, servers, websites, applications and devices, bandwidth, virtual environments, remote systems, IoT, and many more. PRTG is easy to set up & use.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

We are happy to announce a brand new addition to our line of acclaimed email signature management products – CodeTwo Email Signatures for Office 365.
This process describes the steps required to Import and Export data from and to .pst files using Exchange 2010. We can use these steps to export data from a user to a .pst file, import data back to the same or a different user, or even import data t…
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 >>…
The video tutorial explains the basics of the Exchange server Database Availability groups. The components of this video include: 1. Automatic Failover 2. Failover Clustering 3. Active Manager

831 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