Exchange 365 PowerShell – Fix Junk Data with Export-CSV

exchangepowershell

Got one I can't figure out and searching hasn't come up with much. I am trying to export out a list of all mailboxes with sizes. Using a Exchange 365 PowerShell I run the following command:

Get-Mailbox -resultsize unlimited | get-mailboxstatistics | ft DisplayName,TotalItemSize,Itemcount 

And the output is as expected:

DisplayName       TotalItemSize                  ItemCount
-----------       -------------                  ---------
John Smith        1.217 GB (1,306,765,935 bytes)   5935
Jane Doe          3.39 GB (3,639,886,766 bytes)    9505
Bob Johnson       1.663 GB (1,785,801,420 bytes)   5125

I then add a Export-CSV to the command like so:

Get-Mailbox -resultsize unlimited | get-mailboxstatistics | ft DisplayName,TotalItemSize,Itemcount | Export-CSV -Path "C:\Temp\365MailboxSizes.csv" -NoTypeInformation

And the CSV file, other then some incorrect headers, repeats the same identifier the same number of mailboxes I have without any other information:

29c8af9bedd244b2f6b4002fa4af87e
29c8af9bedd244b2f6b4002fa4af87e
29c8af9bedd244b2f6b4002fa4af87e

What would cause the output of the command to not be the same as the Export-CSV? I can copy and paste off the output but the same command works fine on-prem. What am I doing wrong?

Best Answer

greg-askew got me pointed in the right direction. The Format List seemed to be messing things up. Switching to a Select got me the correct output:

Get-Mailbox -resultsize unlimited | get-mailboxstatistics | Select DisplayName,TotalItemSize,Itemcount | Export-CSV -Path "C:\Temp\365MailboxSizes.csv" -NoTypeInformation