We help IT Professionals succeed at work.

How to take inventory of all email address (of contacts, usernames, DLs) from Exchange Server. my server hosts many domains so need a complete list of existing emails

Medium Priority
565 Views
Last Modified: 2012-05-11

i used the script from below URL, works very well.
http://exchangepedia.com/2005/09/how-to-export-all-email-addresses-from-a-domain.html

But the result comes in below format
cn: Performance Log Users
mail: PerformanceLogUsers@xxxxxx
Proxy Addresses
SMTP:PerformanceLogUsers@xxxxxxxx
smtp:PerformanceLogUsers@xxx.com
smtp:PerformanceLogUsers@xxx.net

I want to have the email addresses in the below format

Username1, SMTPAddress,smtpaddress1,smtpaddress2,smtpaddress3
Excluding X.400 smtpaddress

Many thanks
SK

Comment
Watch Question

Commented:
Try this. It should be run in Exchange Management Shell. Tell me if that is not OK for you.
Get-Mailbox | %{
    $mb = $_
    $primary = $mb.primarysmtpaddress.tostring()
    $others3 = @($mb.emailaddresses | ?{$_.prefixstring -eq "smtp" -and $_ -ne $primary}  | Select-Object -First 3)
    New-Object -TypeName PSObject -Property @{
        UserName = $mb.name
        PrimarySMTP = $primary
        SMTPAddress1 = $(if($others3.count -ge 0){$others3[0].smtpaddress}else{""})
        SMTPAddress2 = $(if($others3.count -ge 1){$others3[1].smtpaddress}else{""})
        SMTPAddress3 = $(if($others3.count -ge 2){$others3[2].smtpaddress}else{""})
    }
} | Select-Object Username, PrimarySMTP, SMTPAddress1, SMTPAddress2, SMTPAddress3 | Export-Csv c:\yourpath\yourfile.csv

Open in new window

Commented:
Sorry, I just realized, that you have Exchange 2003. I'll give you a Quest Active Server Role Snapin version soon.

Author

Commented:
Ok thanks Soostibi..

SK

Commented:
So this is the Quest AD snapin PowerShell version. I hope you are familiar with it. (http://www.quest.com/powershell/activeroles-server.aspx )
Get-QADUser -LdapFilter "(mailnickname=*)" | %{
    $mb = $_
    $primary = $mb.proxyaddresses | ?{$_ -clike "SMTP*"} | ForEach-Object {$_ -replace "^SMTP:",""}
    $others3 = @($mb.proxyaddresses | ?{$_ -clike "smtp*"}  | Select-Object -First 3)
    New-Object -TypeName PSObject -Property @{
        UserName = $mb.name
        PrimarySMTP = $primary
        SMTPAddress1 = $(if($others3.count -ge 0){$others3[0]}else{""})
        SMTPAddress2 = $(if($others3.count -ge 1){$others3[1]}else{""})
        SMTPAddress3 = $(if($others3.count -ge 2){$others3[2]}else{""})
    }
} | Select-Object Username, PrimarySMTP, SMTPAddress1, SMTPAddress2, SMTPAddress3  | Export-Csv c:\yourpath\yourfile.csv

Open in new window

Commented:
A bit nicer:
Get-QADUser -LdapFilter "(mailnickname=*)" | %{
    $mb = $_
    $primary = $mb.proxyaddresses | ?{$_ -clike "SMTP*"} | ForEach-Object {$_ -replace "^SMTP:",""}
    $others3 = @($mb.proxyaddresses | ?{$_ -clike "smtp*"}  | ForEach-Object {$_ -replace "^smtp:",""} | Select-Object -First 3)
    New-Object -TypeName PSObject -Property @{
        UserName = $mb.name
        PrimarySMTP = $primary
        SMTPAddress1 = $(if($others3.count -ge 0){$others3[0]}else{""})
        SMTPAddress2 = $(if($others3.count -ge 1){$others3[1]}else{""})
        SMTPAddress3 = $(if($others3.count -ge 2){$others3[2]}else{""})
    }
} | Select-Object Username, PrimarySMTP, SMTPAddress1, SMTPAddress2, SMTPAddress3  | Export-Csv c:\yourpath\yourfile.csv

Open in new window

Author

Commented:
hi, thanks for the script  and just one question before running it, will this include emails from contacts list.

We have a cheaper Axigen box and some users are sitting on that box and there is only contacts available for those users in Active Directory

thanks again
SK
Commented:
Unlock this solution and get a sample of our free trial.
(No credit card required)
UNLOCK SOLUTION

Author

Commented:
Wow that worked like a charm...

Also can you help me with a one script to include contacts, users, groups...

Excellent work!

Many Thanks
SK

Commented:
This includes groups and an additional column describing the object type, such as user, group or contact. Also more precise on users: does not include disabled and system users.
Get-QADObject -LdapFilter "(&(mailnickname=*)(|((&(objectcategory=person)(!(userAccountControl:1.2.840.113556.1.4.803:=2))(!userAccountControl=2080)))(objectClass=contact)(objectClass=group)))" | %{
    $mb = $_
    $primary = $mb.proxyaddresses | ?{$_ -clike "SMTP*"} | ForEach-Object {$_ -replace "^SMTP:",""}
    $others3 = @($mb.proxyaddresses | ?{$_ -clike "smtp*"}  | ForEach-Object {$_ -replace "^smtp:",""} | Select-Object -First 3)
    New-Object -TypeName PSObject -Property @{
        ObjectType = $mb.objectclass | Select-Object -Last 1
        UserName = $mb.name
        PrimarySMTP = $primary
        SMTPAddress1 = $(if($others3.count -ge 0){$others3[0]}else{""})
        SMTPAddress2 = $(if($others3.count -ge 1){$others3[1]}else{""})
        SMTPAddress3 = $(if($others3.count -ge 2){$others3[2]}else{""})
    }
} | Select-Object ObjectType, Username, PrimarySMTP, SMTPAddress1, SMTPAddress2, SMTPAddress3  | Export-Csv c:\yourpath\yourfile.csv

Open in new window

Commented:
And you modify the last portion to:

| Export-Csv c:\yourpath\yourfile.csv  -notypeinfromation

This way it's easier  to open with Excel.

Commented:
Sorry, typo:

| Export-Csv c:\yourpath\yourfile.csv  -NoTypeInformation

Author

Commented:
hi Soostibi... you rock! That's exactly what I wanted...

thanks
SK
Unlock the solution to this question.
Thanks for using Experts Exchange.

Please provide your email to receive a sample view!

*This site is protected by reCAPTCHA and the Google Privacy Policy and Terms of Service apply.

OR

Please enter a first name

Please enter a last name

8+ characters (letters, numbers, and a symbol)

By clicking, you agree to the Terms of Use and Privacy Policy.