We help IT Professionals succeed at work.

Exchange 2010 PowerShell Export to CSV Error

I'm trying to run a report of mailboxes sizes in a database to export to a csv file, however when I run it, the results in the csv file appear as:

#TYPE Microsoft.PowerShell.Commands.Internal.Format.FormatStartData

The command I'm using is:

Get-Mailbox -database "DB04" | Get-MailboxStatistics | Sort totalitemsize -desc | ft displayname, totalitemsize, itemcount | Export-CSV C:\Users\Administrator.DOMAIN\Desktop\mailboxessize.csv

Thank you for your assistance in advance.
Watch Question

Here you go. This is what I use. Enjoy.

Get-Mailbox -ResultSize Unlimited |Select-Object DisplayName, IssueWarningQuota, ProhibitSendQuota, @{label="TotalItemSize(MB)";expression={(Get-MailboxStatistics$_).TotalItemSize.Value.ToMB()}}, @{label="ItemCount";expression={(Get-MailboxStatistics $_).ItemCount}}, Database | Export-Csv"C:\Scripts\UserMailboxSizes.csv" -NoTypeInformation
"Batchelor", Developer and EE Topic Advisor
Top Expert 2015
You should use format-* only for screen output, or if you want a similar formatted content in text files. As a rule of thumb, format-* is always the last command in a pipe.
Why? Because it destroys any additional information about the piped objects, transforming all properties into a single line consisting of strings.

In this particular case you should replace the ft with select-object to get the expected result. You migth want to add the -NoTypeInformation switch to Expert-CSV to skip the type information (#TYPE ...), which is thought to be used for Import-CSV.

Explore More ContentExplore courses, solutions, and other research materials related to this topic.