Solved

Script to pull all exchange primary SMTP addresses and mail attributes

Posted on 2013-06-14
8
1,283 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
Visualize your virtual and backup environments

Create well-organized and polished visualizations of your virtual and backup environments when planning VMware vSphere, Microsoft Hyper-V or Veeam deployments. It helps you to gain better visibility and valuable business insights.

 

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

Best Practices: Disaster Recovery Testing

Besides backup, any IT division should have a disaster recovery plan. You will find a few tips below relating to the development of such a plan and to what issues one should pay special attention in the course of backup planning.

Question has a verified solution.

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

This article explains how to install and use the NTBackup utility that comes with Windows Server.
In-place Upgrading Dirsync to Azure AD Connect
In this video we show how to create a Distribution Group 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 >>…
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…

685 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