• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 643
  • Last Modified:

Exchange 2007 PowerShell Command

How do you export all the email addresses and aliases and sort by domains?

The command below does export all the information but not by domain order.

Get-Mailbox | select name , alias ,EmailAddresses | foreach {
"Name: "+$_.name
"Alias: "+$_.alias

$_.EmailAddresses | foreach {
if($_.SmtpAddress){
if($_.IsPrimaryAddress){
"Primary SmtpAddress: $($_.SmtpAddress)"
} else {
"SmtpAddress: $($_.SmtpAddress)"
}
}
}

write-output ""
} > c:\email-aliases.txt

Just to clarify i want to list all the @test.com in one row and then @test1.com in row 2 etc.

thanks
0
MVTechies
Asked:
MVTechies
  • 8
  • 7
  • 2
1 Solution
 
Manpreet SIngh KhatraSolutions Architect, Project LeadCommented:
Get-Mailbox | Sort-Object Name –Descending | ft name , alias ,EmailAddresses

- Rancy
0
 
MVTechiesAuthor Commented:
Rancy - thanks for the information. However i am after the following format.

first@test.com
second@test.com
third@test.com

and then a list of

first@test2.com
second@test2.com
third@test2.com

etc etc....

Users here have multiple email addresses - the main smtp and then aliases and i want to separate them completely in order of domain i.e. test.com and them test2.com.

thanks
0
 
Rajitha ChimmaniCommented:
Ok..We can sort it out but do you want to sort with PrimarySMTPaddress domain or the normal SMTPAddress domain from your script?
0
Has Powershell sent you back into the Stone Age?

If managing Active Directory using Windows Powershell® is making you feel like you stepped back in time, you are not alone.  For nearly 20 years, AD admins around the world have used one tool for day-to-day AD management: Hyena. Discover why.

 
MVTechiesAuthor Commented:
Just by domain address...

list of all the @test.com for all users all mailboxes in Exchange and then @test2.com and then @test3.com etc.

We need this in either txt or csv format for importing purposes.

thanks
0
 
Rajitha ChimmaniCommented:
While i can work on it...can you tell me which attributes or values must be written in txt or csv file? Just email addresses?
0
 
MVTechiesAuthor Commented:
Just email addresses including aliases and distribution groups are required but sorting on domain name only.

thanks again.
0
 
Rajitha ChimmaniCommented:
Distributiongroups? Which distributiongroups? This was not there in your first script.
0
 
MVTechiesAuthor Commented:
Exchange Distribution Groups if possible. I couldn't find the command for that but if its possible that would be great too.

thanks
0
 
Rajitha ChimmaniCommented:
Do you mean the distribution groups to which that mailbox is memberof? Or the aliases and email addresses of the distribution groups?
0
 
MVTechiesAuthor Commented:
Aliases and email addresses of the distribution groups please.

We need a full export to csv/txt that lists all the email addresses by domain name in different columns.
0
 
Manpreet SIngh KhatraSolutions Architect, Project LeadCommented:
Get-Mailbox | Sort-Object EmailAddresses –Descending | ft name , alias ,EmailAddresses

What if you try with the above count ?

- Rancy
0
 
Rajitha ChimmaniCommented:
Try the below code for mailboxes and if it looks good i will do it for distribution groups as well.

$Mailboxes = @()
Get-Mailbox -Resultsize unlimited | foreach {
$Name = $_.Name
$Alias = $_.alias

$_.EmailAddresses | foreach {
if($_.SmtpAddress){
if($_.IsPrimaryAddress){
[string]$SmtpAddress = $_.SmtpAddress
$IsPrimary = "True"
$Domain = $SmtpAddress.split('@')[1]
}
if(!($_.IsPrimaryAddress)) {
[string]$SmtpAddress = $_.SmtpAddress
$IsPrimary = "False"
$Domain = $SmtpAddress.split('@')[1]
}
}
$MBObject = New-Object System.Object
$MBObject | Add-Member -Name Name -Value $Name -MemberType NoteProperty
$MBObject | Add-Member -Name Alias -Value $Alias -MemberType NoteProperty
$MBObject | Add-Member -Name SMTPAddress -Value $SMTPAddress -MemberType NoteProperty
$MBObject | Add-Member -Name IsPrimary -Value $IsPrimary -MemberType NoteProperty
$MBObject | Add-Member -Name Domain -Value $Domain -MemberType NoteProperty
$Mailboxes += $MBObject
}
}
$Mailboxes | Sort-Object -Property Domain | Export-Csv c:\email-aliases.csv -NoTypeInformation
0
 
MVTechiesAuthor Commented:
thanks for this. It works a treat.

Could you please do the same for distribution groups as well?
0
 
Rajitha ChimmaniCommented:
Use Get-DistributionGroup instead of Get-Mailbox
0
 
MVTechiesAuthor Commented:
Working brilliantly. Thanks for helping.

I've also added in Get-MailPublicFolder which does exactly that in the same format as the others.

Much appreciated.
0
 
MVTechiesAuthor Commented:
Fantastic response and turnaround provided.
0
 
Rajitha ChimmaniCommented:
My pleasure. Enjoy reporting :)
0

Featured Post

VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

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