Solved

Script to pull all exchange primary SMTP addresses and mail attributes

Posted on 2013-06-14
8
1,242 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
Better Security Awareness With Threat Intelligence

See how one of the leading financial services organizations uses Recorded Future as part of a holistic threat intelligence program to promote security awareness and proactively and efficiently identify threats.

 

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

The problems with reply email signatures

Do you wish that you could place an email signature under a reply? Well, unfortunately, you can't. That great Exchange/Office 365 signature you've created will just appear at the bottom of an email chain. What a pain! Is there really no way to solve this? Well, there might be...

Join & Write a Comment

Check out this infographic on what you need to make a good email signature that will work perfectly for your organization.
Following basic email etiquette rules will help you write a professional email and achieve a good, lasting impression with your contacts.
In this video we show how to create a Shared Mailbox 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 >> Sha…
In this video we show how to create a Resource Mailbox in Exchange 2013. We show this process by using the Exchange Admin Center. Log into Exchange Admin Center.: Navigate to the Recipients >> Resources tab.: "Recipients" is our default selection …

762 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

20 Experts available now in Live!

Get 1:1 Help Now