Solved

List of all email addresses set up in Exchange 2010

Posted on 2013-12-16
12
379 Views
Last Modified: 2013-12-18
I need to obtain a list of all email addresses set up in Exchange 2010.
0
Comment
Question by:100questions
  • 6
  • 6
12 Comments
 
LVL 19

Accepted Solution

by:
jss1199 earned 500 total points
ID: 39721358
From the Exchange shell (Powershell), run the below - modify the output path as desired:

Get-recipient -resultsize unlimited | select Name -expand emailaddresses | Select SmtpAddress > c:\emailaddys.txt

Open in new window

0
 

Author Comment

by:100questions
ID: 39721366
Thanks. PowerShell was attempted to be used in the past and the server would not allow it.
0
 
LVL 19

Expert Comment

by:jss1199
ID: 39721392
Strange... I would open another topic to get to the bottom of why PS doesn't work on your Exchange Server.  I suspect it was a bad script previously, but if not you need to get to the bottom.  VBS is so 1990 :)

'==================================================================================================
' 
' VBScript Source File 
' 
' NAME: LISTPROXYADDRESSES.VBS 
' VERSION: 0.9.1 
' AUTHOR: Bharat Suneja , Nick Phipps 
' LAST MODIFIED : 19/04/2011 
'==================================================================================================
' COMMENT: 
' 
'==================================================================================================
'Set up constant for deleting values from multivalued attribute memberOf
option explicit
on error resume next
Const ADS_PROPERTY_NOT_FOUND = &h8000500D 
Const ADS_UF_ACCOUNTDISABLE = 2 'For UserAccountControl 
Const strX400Search = "X400"
dim strDomain 
dim strADPath 
dim objDomain 
dim strOutput 
dim boolTestMode 
dim objRootDSE 
dim objConnection 
dim objCommand 
dim objRecordSet 
dim strResult 
dim AddressCount 
dim strUserDN 
dim objUser 
dim ArrProxyAddresses 
dim proxyAddress
'______________________________________________________
'### Change the following line to change the output file path and name 
strOutput = ".\email_addresses.txt"
'### Change the following line to "True" to change output to a dialog instead of a TXT file 
boolTestMode = false
'Set RootDSE 
Set objRootDSE = GetObject("LDAP://rootDSE") 
strDomain = objRootDSE.Get("defaultNamingContext") 
strADPath = "LDAP://" & strDomain 
wscript.Echo strADPath 
Set objDomain = GetObject(strADPath) 
wscript.echo "objDomain: " & objDomain.distinguishedName
'Setup ADODB connection 
Set objConnection = CreateObject("ADODB.Connection") 
objConnection.Open "Provider=ADsDSOObject;" 
Set objCommand = CreateObject("ADODB.Command") 
objCommand.ActiveConnection = objConnection
'Execute search command to look for Contacts & Groups 
objCommand.CommandText = _ 
"<" & strADPath & ">" & ";(&(|(objectClass=contact)(objectClass=group))(mail=*))" & ";distinguishedName,displayName,mail,proxyAddresses;subtree"
'Execute search to get Recordset 
Set objRecordSet = objCommand.Execute 


'Start procedure 

strResult = strResult & VbCrLf & "Domain: " & strDomain
strResult = strResult & VbCrlf & "#Total Records Found (other accounts): " & objRecordSet.RecordCount & VbCrlf 
AddressCount = 0
While Not objRecordSet.EOF 'Iterate through the search results 

strUserDN = objRecordSet.Fields("distinguishedName") 'Get User's distinguished name from Recordset into a string 
wscript.Echo "strUserDN: "& strUserDN 

set objUser= GetObject("LDAP://"& strUserDN & "") 'Use string to bind to user object 
If Err.Number <> 0 Then 
Wscript.Echo Computer & " " & Err.Description 
Err.Clear 
Else 
strResult = strResult & VbCrlf & "cn: " & objUser.cn 
strResult = strResult & VbCrlf & "mail: " & objUser.mail 
arrProxyAddresses = objRecordSet.Fields("proxyAddresses") 
If IsArray(objRecordSet.Fields("proxyAddresses")) Then 
strResult = strResult & VbCrLf & "Proxy Addresses" 

For Each ProxyAddress in arrProxyAddresses 

'Sub: Check X400 
If InStr(ProxyAddress, strX400Search) <> 0 Then 
'Wscript.Echo "#This was an x400" 
Else 
strResult = strResult & VbCrlf & proxyAddress 
End If 'Ends loop for X400 address 
Next
Else 
strResult = strResult & VbCrlf & "#Object does not have proxy addresses" 
End If 
strResult = strResult & VbCrLf 
end if 
objRecordSet.MoveNext 
Wend
'************************************* 
'Begin second query for users 
varDisabledCounter = 0
'Execute search command to look for user 
objCommand.CommandText = _ 
"<" & strADPath & ">" & ";(&(objectClass=user)(mail=*))" & ";distinguishedName,displayName,mail,proxyAddresses;subtree"
'Execute search to get Recordset 
Set objRecordSet = objCommand.Execute 

strResult = strResult & vbCrlf & "#Users" 
strResult = strResult & VbCrlf & "#Total Records Found (users): " & objRecordSet.RecordCount & VbCrlf 

' Wscript.Echo strResult
While Not objRecordSet.EOF 'Iterate through the search results 
strUserDN = objRecordSet.Fields("distinguishedName") 'Get User's distinguished name from Recordset into a string 
set objUser= GetObject("LDAP://"& strUserDN & "") 'Use string to bind to user object 
If Err.Number <> 0 Then 
Wscript.Echo Computer & " " & err.number & " " & Err.Description 
Err.Clear 
Else 

If objUser.AccountDisabled = TRUE Then 'If User account disabled, then skip proxy address enum 
varDisabledCounter = varDisabledCounter + 1 
strResult2 = strResult2 & VbCrLf & varDisabledCounter & " " & objUser.displayName & VbCrLf 

strResult2 = strResult2 & "cn: " & objUser.cn 
strResult2 = strResult2 & VbCrlf & "mail: " & objUser.mail 
arrProxyAddresses = objRecordSet.Fields("proxyAddresses") 
If IsArray(objRecordSet.Fields("proxyAddresses")) Then 
strResult2 = strResult2 & VbCrLf & "Proxy Addresses" 


For Each ProxyAddress in arrProxyAddresses 
'Sub: Check X400 
If InStr(ProxyAddress, strX400Search) <> 0 Then 
'Wscript.Echo "#This was an x400" 
Else 
strResult2 = strResult2 & VbCrlf & proxyAddress 
AddressCount = AddressCount + 1 
End If 'Ends loop for X400 address 
Next 
Else 
strResult2 = strResult2 & VbCrLf & "#Object does not have proxy addresses" 
End If 
strResult2 = strResult2 & VbCrLf 





Else 
strResult = strResult & VbCrlf & "cn: " & objUser.cn 
strResult = strResult & VbCrlf & "mail: " & objUser.mail 
arrProxyAddresses = objRecordSet.Fields("proxyAddresses") 
If IsArray(objRecordSet.Fields("proxyAddresses")) Then 
strResult = strResult & VbCrLf & "Proxy Addresses" 

For Each ProxyAddress in arrProxyAddresses 
'Sub: Check X400 
If InStr(ProxyAddress, strX400Search) <> 0 Then 
'Wscript.Echo "#This was an x400" 
Else 
strResult = strResult & VbCrlf & proxyAddress 
AddressCount = AddressCount + 1 
End If 'Ends loop for X400 address 
Next 
Else 
strResult = strResult & VbCrLf & "#Object does not have proxy addresses" 
End If 
strResult = strResult & VbCrLf 

End If 'End check for disabled user 
end if ' error 
objRecordSet.MoveNext 
Wend 'End second query for users

strResult = "Users, Groups & Contacts" & VbCrLf & "-------------------------" & VbCrLf & strResult 
strResult = strResult & VbCrLf & "Disabled Users" & VbCrLf & "-------------------------" & VbCrLf & strResult2
'Output results 
' if boolTestMode then 
wscript.echo "strResult contains:" 
WScript.Echo strResult 
wscript.echo "strResult2 contains:" 
wscript.echo strResult2 
wscript.echo "End of strResults" 

' else 
'Output to a text file 
Set objFileSystem = CreateObject("Scripting.FileSystemObject") 
Set objOutputFile = objFileSystem.CreateTextFile(strOutput) 
objOutputFile.Write strResult 
objoutputfile.close 
' end if
WScript.Echo "Done."

Open in new window

0
 

Author Comment

by:100questions
ID: 39721423
Thanks. Where is the output file written?
Say I wanted to write it at C:\Addresses\... how do I get it to write to a file called
C:\Addresses\emailaddresses.txt ?
0
 
LVL 19

Expert Comment

by:jss1199
ID: 39721430
Change line 63 above to the location and filename you want
0
 

Author Comment

by:100questions
ID: 39721436
The output file is not written anywhere, even when I change the path.
And the pop up message I see does not allow me to scroll through it so that I can see all the user emails.
0
Comprehensive Backup Solutions for Microsoft

Acronis protects the complete Microsoft technology stack: Windows Server, Windows PC, laptop and Surface data; Microsoft business applications; Microsoft Hyper-V; Azure VMs; Microsoft Windows Server 2016; Microsoft Exchange 2016 and SQL Server 2016.

 

Author Comment

by:100questions
ID: 39721486
The output file is not written anyhwere.  Also, even when I change the script to say True it does not output to the screen all of the records.  It says I have several records however it only displays a few.  This does not seem to work properly.
0
 
LVL 19

Expert Comment

by:jss1199
ID: 39721500
Works fine against my E2010 and 2013 environments.  I'll take a closer look at the script.  

Fixed your Powershell yet?
0
 

Author Comment

by:100questions
ID: 39721673
Exhange PowerShell is working, it's regujlar PowerShell which I had trouble with in the past.
Exchange script worked however it does not show me mailbox name that it's associated with, just the email addresses of local and .com.

I would still like the VBScript to work as as backup, at least so that I can see all multiple users on the screen and copy the data, if it can't write the file.
0
 
LVL 19

Expert Comment

by:jss1199
ID: 39721679
The original request asked for only email addresses so the was the PS command provided. I'll update in a moment to include mailbox
0
 
LVL 19

Expert Comment

by:jss1199
ID: 39721694
Get-Mailbox -ResultSize Unlimited |Select-Object DisplayName,ServerName,PrimarySmtpAddress, @{Name=“EmailAddresses”;Expression={$_.EmailAddresses |Where-Object {$_.PrefixString -ceq “smtp”} | ForEach-Object {$_.SmtpAddress}}} > C:\Addresses\emailaddresses.txt

Open in new window

0
 

Author Comment

by:100questions
ID: 39724450
Thanks.  The size of the width of for the email addresses is not wide enough, they get cut off.
Also, any success with the VBScript.
0

Featured Post

Get up to 2TB FREE CLOUD per backup license!

An exclusive Black Friday offer just for Expert Exchange audience! Buy any of our top-rated backup solutions & get up to 2TB free cloud per system! Perform local & cloud backup in the same step, and restore instantly—anytime, anywhere. Grab this deal now before it disappears!

Join & Write a Comment

Microsoft has released remote PowerShell capabilities to all commercial Office 365 customers. So you can be controlled via PowerShell and not from the Office 365 admin center Download Windows PowerShell Module for Lync Online http://www.micros…
User Beware!  This is a rather permanent solution to removing your email from an exchange server.  The only way to truly go back is to have your exchange administrator restore your mailbox from backups.  This is usually the option of last resort.  A…
Viewers will learn the different options available in the Backstage view in Excel 2013.
The viewer will learn how to simulate a series of sales calls dependent on a single skill level and learn how to simulate a series of sales calls dependent on two skill levels. Simulating Independent Sales Calls: Enter .75 into cell C2 – “skill leve…

707 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

13 Experts available now in Live!

Get 1:1 Help Now