Take the 2-minute tour ×
Server Fault is a question and answer site for system and network administrators. It's 100% free, no registration required.

I need to dump only the primary SMTP addresses to a .csv file. I need to do this for all Users, Groups and Mail Enabled PFs. Environment is Exchange 2007/2010. I have been trying to work with the following EMS commands, but I get all email addresses instead of just the primary address.

get-mailbox | %{$_.EmailAddresses} | %{$_.SmtpAddress} | out-file c:\mailboxes.csv
get-distributiongroup | %{$_.EmailAddresses} | %{$_.SmtpAddress} | out-file c:\distributiongroups.csv
get-contact | %{$_.WindowsEmailAddress} | %{$_.Local + "@" + $_.Domain} | out-file c:\contacts.csv
get-mailpublicfolder | %{$_.EmailAddresses} | %{$_.SmtpAddress} | out-file c:\mailpublicfolders.csv

I fear I've made a syntax error, but cannot spot it at present. I'd like to avoid parsing the .csv file unless that's the only viable option.

share|improve this question

1 Answer 1

You are looping through all of the email addresses for each user, so of course you're going to get all of the email addresses. (% is shorthand for the foreach operator).

You should just use the PrimarySmtpAddress attribute:

get-mailbox | select-object PrimarySmtpAddress | out-file c:\mailboxes.csv
get-distributiongroup | select-object PrimarySmtpAddress | out-file c:\distributiongroups.csv
get-contact | select-object PrimarySmtpAddress | out-file c:\contacts.csv
get-mailpublicfolder | select-object PrimarySmtpAddress | out-file c:\mailpublicfolders.csv
share|improve this answer

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.