Link to home
Start Free TrialLog in
Avatar of MVTechies
MVTechiesFlag for United Kingdom of Great Britain and Northern Ireland

asked on

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
Avatar of Manpreet SIngh Khatra
Manpreet SIngh Khatra
Flag of India image

Get-Mailbox | Sort-Object Name –Descending | ft name , alias ,EmailAddresses

- Rancy
Avatar of MVTechies

ASKER

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
Ok..We can sort it out but do you want to sort with PrimarySMTPaddress domain or the normal SMTPAddress domain from your script?
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
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?
Just email addresses including aliases and distribution groups are required but sorting on domain name only.

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

thanks
Do you mean the distribution groups to which that mailbox is memberof? Or the aliases and email addresses of the distribution groups?
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.
Get-Mailbox | Sort-Object EmailAddresses –Descending | ft name , alias ,EmailAddresses

What if you try with the above count ?

- Rancy
ASKER CERTIFIED SOLUTION
Avatar of Rajitha Chimmani
Rajitha Chimmani
Flag of United States of America 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
thanks for this. It works a treat.

Could you please do the same for distribution groups as well?
Use Get-DistributionGroup instead of Get-Mailbox
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.
Fantastic response and turnaround provided.
My pleasure. Enjoy reporting :)