Solved

Need script to generate list of all email accounts in Active Directory 2003

Posted on 2007-12-04
5
2,167 Views
Last Modified: 2010-12-21
I need a script that will give me a .csv file of all email accounts in active directory (2003) .I don't need any info associated with the account,etc. Just need a list of all active email addresses.
0
Comment
Question by:FIFBA
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
5 Comments
 
LVL 70

Expert Comment

by:KCTS
ID: 20407491
0
 

Author Comment

by:FIFBA
ID: 20407834
Is there a way to get the email address only into a csv file?
0
 
LVL 12

Accepted Solution

by:
chandru_sol earned 500 total points
ID: 20408413
Try this script.........

Save the script as listemail.vbs

From the command prompt where the script resides run
cscript listemail.vbs > listemailaddress.csv

regards
Chandru
Option Explicit
 
Dim objRootDSE, strDNSDomain, objCommand, objConnection
Dim strBase, strFilter, strAttributes, strQuery, objRecordSet
Dim strNTName, strDN, colmail, strmail, stremail, strOU
 
' 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 = "<LDAP://" & strDNSDomain & ">"
 
' 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"
Else
' 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
Next 
End If
Wscript.Echo strNTName & "," & strEmail
objRecordSet.MoveNext
Loop
objRecordSet.Close
 
' Clean up.
objConnection.Close
Set objRootDSE = Nothing
Set objCommand = Nothing
Set objConnection = Nothing
Set objRecordSet = Nothing
'===============

Open in new window

0
 
LVL 12

Expert Comment

by:chandru_sol
ID: 20412447
Thanks FIFBA!
0
 

Expert Comment

by:dapopa9
ID: 21799364
thanks!
0

Featured Post

Get free NFR key for Veeam Availability Suite 9.5

Veeam is happy to provide a free NFR license (1 year, 2 sockets) to all certified IT Pros. The license allows for the non-production use of Veeam Availability Suite v9.5 in your home lab, without any feature limitations. It works for both VMware and Hyper-V environments

Question has a verified solution.

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

Setting up a Microsoft WSUS update system is free relatively speaking if you have hard disk space and processor capacity.   However, WSUS can be a blessing and a curse. For example, there is nothing worse than approving updates and they just have…
ADCs have gained traction within the last decade, largely due to increased demand for legacy load balancing appliances to handle more advanced application delivery requirements and improve application performance.
Monitoring a network: why having a policy is the best policy? Michael Kulchisky, MCSE, MCSA, MCP, VTSP, VSP, CCSP outlines the enormous benefits of having a policy-based approach when monitoring medium and large networks. Software utilized in this v…
Do you want to know how to make a graph with Microsoft Access? First, create a query with the data for the chart. Then make a blank form and add a chart control. This video also shows how to change what data is displayed on the graph as well as form…

632 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