Score:0

Addition of Export-CSV to command in Exchange 365 PowerShell results in junk data while display output is correct

ph flag
ADY

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?

cn flag
Maybe not use a format table operator? `New-Object PSObject` is a better fit there.
ADY avatar
ph flag
ADY
That was it. I'd say its weird that On Prem has no issues with this but there are so many little quirks with Exchange 365 that this isn't surprising. I changed my Format List over to a Select and the CSV file looks perfect.
Score:0
ph flag
ADY

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
br flag
as you learned ... NEVER use the `Format-*` cmdlets for anything other than FINAL output to the screen or a plain text item [like a file]. take a look at the error you get with >>> `(Get-ChildItem -LiteralPath $env:TEMP -File | Format-Table)[2]` <<<. note the `The object of type Microsoft.PowerShell.Commands.Internal.Format.FormatEntryData"` mentioned there. [*grin*]
mangohost

Post an answer

Most people don’t grasp that asking a lot of questions unlocks learning and improves interpersonal bonding. In Alison’s studies, for example, though people could accurately recall how many questions had been asked in their conversations, they didn’t intuit the link between questions and liking. Across four studies, in which participants were engaged in conversations themselves or read transcripts of others’ conversations, people tended not to realize that question asking would influence—or had influenced—the level of amity between the conversationalists.