Want to protect your cyber security and still get fast solutions? Ask a secure question today.Go Premium

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 416
  • Last Modified:

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

0
principiamanagement
Asked:
principiamanagement
  • 8
  • 4
1 Solution
 
soostibiCommented:
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

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

SK
0
Who's Defending Your Organization from Threats?

Protecting against advanced threats requires an IT dream team – a well-oiled machine of people and solutions working together to defend your organization. Download our resource kit today to learn more about the tools you need to build you IT Dream Team!

 
soostibiCommented:
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

0
 
soostibiCommented:
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

0
 
principiamanagementAuthor 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
0
 
soostibiCommented:
This gives both users and contacts.
Get-QADObject -LdapFilter "(&(mailnickname=*)(|(objectClass=user)(objectClass=contact)))" | %{
    $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

0
 
principiamanagementAuthor 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
0
 
soostibiCommented:
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

0
 
soostibiCommented:
And you modify the last portion to:

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

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

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

thanks
SK
0

Featured Post

Prepare for your VMware VCP6-DCV exam.

Josh Coen and Jason Langer have prepared the latest edition of VCP study guide. Both authors have been working in the IT field for more than a decade, and both hold VMware certifications. This 163-page guide covers all 10 of the exam blueprint sections.

  • 8
  • 4
Tackle projects and never again get stuck behind a technical roadblock.
Join Now