Solved

Script to pull all exchange primary SMTP addresses and mail attributes

Posted on 2013-06-14
8
1,305 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
[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
  • 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
Use Case: Protecting a Hybrid Cloud Infrastructure

Microsoft Azure is rapidly becoming the norm in dynamic IT environments. This document describes the challenges that organizations face when protecting data in a hybrid cloud IT environment and presents a use case to demonstrate how Acronis Backup protects all data.

 

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

Forrester Webinar: xMatters Delivers 261% ROI

Guest speaker Dean Davison, Forrester Principal Consultant, explains how a Fortune 500 communication company using xMatters found these results: Achieved a 261% ROI, Experienced $753,280 in net present value benefits over 3 years and Reduced MTTR by 91% for tier 1 incidents.

Question has a verified solution.

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

MS Outlook is a world-class email client application that is mainly used for e-communication globally.  In this article, we will discuss the basic idea about MS Outlook, its advanced features, and types of MS Outlook File formats.
In-place Upgrading Dirsync to Azure AD Connect
In this Micro Video tutorial you will learn the basics about Database Availability Groups and How to configure one using a live Exchange Server Environment. The video tutorial explains the basics of the Exchange server Database Availability grou…
The basic steps you have just learned will be implemented in this video. The basic steps are shown to configure an Exchange DAG in a live working Exchange Server Environment and manage the same (Exchange Server 2010 Software is used in a Windows Ser…

752 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