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
"ClassId2e4f51ef21dd47e99d3c952918aff9cd","pageHeaderEntry","pageFooterEntry","autosizeInfo","shapeInfo","groupingEntry"
"033ecb2bc07a4d43b5ef94ed5a35d280",,,,"Microsoft.PowerShell.Commands.Internal.Format.TableHeaderInfo",
"9e210fe47d09416682b841769c78b8a3",,,,,
"27c87ef9bbda4f709f6b4002fa4af63c",,,,,
"27c87ef9bbda4f709f6b4002fa4af63c",,,,,

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.
Comment
Watch Question

Commented:
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
CERTIFIED EXPERT
Top Expert 2015
Commented:
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.