Link to home
Start Free TrialLog in
Avatar of principiamanagement
principiamanagementFlag for Indonesia

asked on

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


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

Avatar of soostibi
soostibi
Flag of Hungary image

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

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

ASKER

Ok thanks Soostibi..

SK
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

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

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
ASKER CERTIFIED SOLUTION
Avatar of soostibi
soostibi
Flag of Hungary image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
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
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

And you modify the last portion to:

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

This way it's easier  to open with Excel.
Sorry, typo:

| Export-Csv c:\yourpath\yourfile.csv  -NoTypeInformation
hi Soostibi... you rock! That's exactly what I wanted...

thanks
SK