Exchange 2007 PrimarySMTP CSV List

Posted on 2011-10-14
Last Modified: 2012-05-12
I need help in creating a very simple powershell script in Exchange 2007.  We implemented Google GMC and this requires a simple CSV file listing all primary email addresses.

I need to daily export a list of primary email addresses for all active users in specific org units.  The list should simply look as follow:

Any expert out there than can help me with this?

Thanks in advance!
Question by:SFCG
    LVL 10

    Expert Comment

    Just the email addresses?
    get-mailbox | select PrimarySMTPAddress

    Open in new window


    Author Comment

    No, I need this to be exported to a CSV file, but formated without the first line nor the quotes on each email address and from specific OUs in my Active Directory.

    I have this, but I don't know how to change the formatting nor to select only specific OUs:
    Get-Mailbox | select PrimarySmtpAddress | Export-CSV C:\temp\allmailboxes.csv

    Any other ideas?  Thanks.

    Accepted Solution

    I ended up running it as a DSQuery as follow at it worked perfectly for Google Message Continuity.  Thanks!
    dsquery * OU=Users,DC=domain,DC=com -limit 0 -filter "(&(objectCategory=person)(objectClass=user)(mail=*))" -attr mail >"c:\temp\PrimaryEmailAddresses1.csv"
    more +1 "c:\temp\PrimaryEmailAddresses1.csv" > "c:\temp\PrimaryEmailAddresses.csv"
    del "c:\temp\PrimaryEmailAddresses1.csv"

    Open in new window


    Author Closing Comment

    After spending a few hours trying different things this accomplished for I was looking for.
    LVL 9

    Expert Comment

    Just throwing it out there but this should also do the trick:

    Get-Mailbox -OrganizationalUnit "OU=Users,DC=domain,DC=com" | Select PrimarySMTPAddress | Export-CSV "C:\Some Folder\file.csv" -NoType

    Author Comment

    Chris, that also works, but I would still need to delete the first line.  Thanks!

    Featured Post

    Too many email signature updates to deal with?

    Are you constantly visiting users’ desks making changes to email signatures? Feel like it’s taking up all of your time? Wish you could manage all signatures from one central location, easily design them and deploy them quickly to users? Well, there is an easy way!

    Join & Write a Comment

    Email statistics and Mailbox database quotas You might have an interest in attaining information such as mailbox details, mailbox statistics and mailbox database details from Exchange server. At that point, knowing how to retrieve this information …
    Check out this infographic on what you need to make a good email signature that will work perfectly for your organization.
    To show how to create a transport rule in Exchange 2013. We show this process by using the Exchange Admin Center. Log into Exchange Admin Center.: First we need to log into the Exchange Admin Center. Navigate to the Mail Flow >> Rules tab.:  To cr…
    how to add IIS SMTP to handle application/Scanner relays into office 365.

    728 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    14 Experts available now in Live!

    Get 1:1 Help Now