Get-Mailbox & Get-MailboxStatistics displays on screen but do not export to CSV

Wondered if some genius could help me out here! :)

I've put together a command that will give me a list of mailboxes in a particular OU, and to list by DisplayName, WhenCreated & LastLogon. 

If I run the following command it displays fine on-screen:

Get-Mailbox -resultsize unlimited -OrganizationalUnit "domain.com/Applications/Mail/Contacts and Mailboxes/com/domain" | ft DisplayName,WhenCreated,@{e={ ((Get-MailboxStatistics $_.name).Lastlogontime)};l='Last Logon Time'} -Autosize

However, if I add the export-csv command, it only populates the CSV with a bunch of HEX numbers.

Get-Mailbox -resultsize unlimited -OrganizationalUnit "domain.com/Applications/Mail/Contacts and Mailboxes/com/domain" | ft DisplayName,WhenCreated,@{e={ ((Get-MailboxStatistics $_.name).Lastlogontime)};l='Last Logon Time'} -Autosize | export-csv c:\mailboxlist.csv

Any ideas?

Thanks in advance.

Mike.

May 20th, 2015 11:56am

Don't pipe a Format-Table command into an Export-CSV command. One way to think of it is that Export-CSV effectively replaces Format-Table. I would change your "FT" to "select" so you still get the columns you desire and pipe that to your Export-CSV instead.
  • Edited by ThmsRynrMVP 15 hours 31 minutes ago spelling
Free Windows Admin Tool Kit Click here and download it now
May 20th, 2015 12:00pm

Don't pipe a Format-Table command into an Export-CSV command. One way to think of it is that Export-CSV effectively replaces Format-Table. I would change your "FT" to "select" so you still get the columns you desire and pipe that to your Export-CSV instead.
  • Edited by ThmsRynrMVP Wednesday, May 20, 2015 3:58 PM spelling
  • Marked as answer by Michael Keel 18 hours 15 minutes ago
May 20th, 2015 3:58pm

Thanks. I also removed the -Autosize switch. The following now works:

Get-Mailbox -resultsize unlimited -OrganizationalUnit "domain.com/Applications/Mail/Contacts and Mailboxes/com/domain" | select DisplayName,WhenCreated,@{e={ ((Get-MailboxStatistics $_.name).Lastlogontime)};l='Last Logon Time'} | export-csv c:\mailboxlist.csv

Mike.

Free Windows Admin Tool Kit Click here and download it now
May 21st, 2015 9:18am

This topic is archived. No further replies will be accepted.

Other recent topics Other recent topics