Exporting mailbox information to CSV for one particular domain or one OU


I have an Exchange 2013 server which handles email for about 5 different domains.
I need to export to PST all mailboxes for one of these domains.

Part 1.
1.I would like to first gather the following in CSV: Name of User | Email Address | Mailbox Size
2.I've tried various commands exporting to details to CSV, but when I open the CSV, I find that all the data is in a single cell rather than separate columns.  Can you furnish the appropriate command to address this issue?

Part 2
1.Also is it possible to export this information only for mailboxes with the particular email domain (all users whose email address ends with domain2.com?
2.Can it export information only from one particular Organization Unit?

Thanks in advance.

Who is Participating?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

timgreen7077Exchange EngineerCommented:
Try the below. This should give you what you need.

$DataPath = "C:\temp\results.csv"
$Results = @()
$MailboxUsers = get-mailbox -resultsize unlimited | where {$_.organizationalunit -like "Enter the OU Path"}
foreach($user in $mailboxusers)
$UPN = $user.UserPrincipalName
$MbxStats = Get-MailboxStatistics $UPN
$UserNotes = Get-User $UPN
      $Properties = @{
      Name = $user.name
      UPN = $UPN
      Alias = $user.alias
      OU = $user.organizationalunit
      Server = $MbxStats.servername
      Database = $MbxStats.databasename
      TotaItemSize = $MbxStats.totalitemsize
$Results += New-Object psobject -Property $properties
$Results | Sort-Object -Property TotaItemSize | Select-Object Name,UPN,Alias,OU,Server,Database,TotaItemSize | Export-Csv -notypeinformation -Path $DataPath

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today

From novice to tech pro — start learning today.