Solved

Script to pull all exchange primary SMTP addresses and mail attributes

Posted on 2013-06-14
8
1,257 Views
Last Modified: 2013-07-08
Hi we are having issues with our GAL because some of our user's mail does not equal to the SMTP primary address. Is there a script that I can use to extract name, sAMAccountName, mail and primarySMTP address to a csv or excel?

PLease help.

Thank you,.
0
Comment
Question by:syseng007
  • 4
  • 4
8 Comments
 

Author Comment

by:syseng007
ID: 39248812
I got this but I get the "Object not a collection" error.

'=======================================================================================
'
' COMMENT:       Exports a list of users with a specific SMTP domain in their proxy addreses
'=======================================================================================

Const ForWriting = 2

'Domain to be processes
strSMTPDomain = "domain.com"
intSDLen = Len(strSMTPDomain)

'Path for the output file
filePath = "C:\" & strSMTPDomain & ".txt"

'Setup output file
Set objFSO = CreateObject("Scripting.FileSystemObject")
Set objTextFile = objFSO.OpenTextFile(filepath, ForWriting, True)

'Create Objects for LDAP Queries
Set rootDSE = GetObject("LDAP://RootDSE")
DomainContainer = rootDSE.Get("defaultNamingContext")

Set conn = CreateObject("ADODB.Connection")
conn.Provider = "ADSDSOObject"
conn.Open "ADs Provider"

'LDAP query for all mail users
strLDAP = "<LDAP://" & DomainContainer & ">;(&(mail=*)(objectCategory=person)(objectClass=user));adspath;subtree"

'Get query results and output to file
Set oComm = CreateObject("ADODB.Command")
oComm.ActiveConnection = conn
oComm.CommandText = strLDAP
oComm.Properties("Sort on") = "DisplayName"
oComm.Properties("Page size") = 1500
Set rs = oComm.Execute

While Not rs.EOF
      
      Set FoundObject = GetObject (rs.Fields(0).Value)
      arrProxyAddresses = FoundObject.proxyAddresses
      For Each Address In arrProxyAddresses
            If left(Address,5)= "smtp:" And Right(LCase(Address),intSDLen)= strSMTPDomain Then
                   objTextFile.WriteLine(Address)
            End if
      Next
    rs.MoveNext
      
Wend

MsgBox "Processing complete!"
0
 
LVL 40

Accepted Solution

by:
Subsun earned 500 total points
ID: 39249083
Which version of exchange you have?

If you are OK with PowerShell script then try this..

Get-QADUser -SizeLimit 0 | Select Name,PrimarySMTPAddress,Mail | Export-CSV c:\report.csv -NTI

Open in new window

The code require Quest AD shell (This is a free and very useful tool can be installed on any computer connected to your domain)
http://www.quest.com/powershell/activeroles-server.aspx
0
 
LVL 40

Expert Comment

by:Subsun
ID: 39249114
Or you can use ldifde, change "dc=Test,dc=com"test.com to your domain name in following command.
ldifde -f proxies.txt -d "dc=Test,dc=com" -l "Mail,proxyaddresses" -r "(proxyaddresses=smtp:*@test.com)"

Open in new window

0
 

Author Comment

by:syseng007
ID: 39253278
@subsun - It is exchange 2003
0
Free book by J.Peter Bruzzese, Microsoft MVP

Are you using Office 365? Trying to set up email signatures but you’re struggling with transport rules and connectors? Let renowned Microsoft MVP J.Peter Bruzzese show you how in this exclusive e-book on Office 365 email signatures. Better yet, it’s free!

 

Author Comment

by:syseng007
ID: 39253301
@subsun - I get this error message after executing the powershell command. PLease advise. Thank you.

The term 'Get-QADUser' is not recognized as the name of a cmdlet, function, scr
ipt file, or operable program. Check the spelling of the name, or if a path was
 included, verify that the path is correct and try again.
At line:1 char:12
+ Get-QADUser <<<<  -SizeLimit 0 | Select Name,PrimarySMTPAddress,Mail | Export
-CSV c:\report.csv -NTI
    + CategoryInfo          : ObjectNotFound: (Get-QADUser:String) [], Command
   NotFoundException
    + FullyQualifiedErrorId : CommandNotFoundException
0
 
LVL 40

Expert Comment

by:Subsun
ID: 39253336
The code require Quest AD shell (This is a free and very useful tool can be installed on any computer connected to your domain)
http://www.quest.com/powershell/activeroles-server.aspx 

Do you have Quest AD shell?
0
 

Author Comment

by:syseng007
ID: 39253384
@Subsun - it worked! Thank you so much! Do you recommend some sites of commonly used powershell commands as far as administering AD objects..or server objects? Thanks again!
0
 
LVL 40

Expert Comment

by:Subsun
ID: 39253421
There are many.. :-)

IMO, The PowerShell Help actually helps..

Help <Your command>

For example..
Help Get-QADUser -Full
Help Get-QADUser -Examples

You can also download ActiveRoles Management Shell for Active Directory - Administrator's Guide from above link which I provided..

Other ref :
http://ss64.com/ps/quest.html
http://ss64.com/ps/ad.html
http://www.powershellpro.com/powershell-tutorial-introduction/tutorial-powershell-cmdlet/
0

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Follow this checklist to learn more about the 15 things you should never include in an email signature from personal quotes, animated gifs and out-of-date marketing content.
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 an Accepted Domain 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 Mail Flow >> Ac…
In this video we show how to create an email address policy 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 Mail Flow…

867 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

22 Experts available now in Live!

Get 1:1 Help Now