Solved

Script to pull all exchange primary SMTP addresses and mail attributes

Posted on 2013-06-14
8
1,263 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
VMware Disaster Recovery and Data Protection

In this expert guide, you’ll learn about the components of a Modern Data Center. You will use cases for the value-added capabilities of Veeam®, including combining backup and replication for VMware disaster recovery and using replication for data center migration.

 

Author Comment

by:syseng007
ID: 39253278
@subsun - It is exchange 2003
0
 

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

Three Reasons Why Backup is Strategic

Backup is strategic to your business because your data is strategic to your business. Without backup, your business will fail. This white paper explains why it is vital for you to design and immediately execute a backup strategy to protect 100 percent of your data.

Question has a verified solution.

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

Utilizing an array to gracefully append to a list of EmailAddresses
Scam emails are a huge burden for many businesses. Spotting one is not always easy. Follow our tips to identify if an email you receive is a scam.
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
This video shows how to quickly and easily add an email signature for all users on Exchange 2016. The resulting signature is applied on a server level by Exchange Online. The email signature template has been downloaded from: www.mail-signatures…

776 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