Link to home
Start Free TrialLog in
Avatar of chadkline
chadklineFlag for United States of America

asked on

Exchange Management Shell Error

Trying to produce a report using Exchange Management Shell for mailbox statistics.

Here is what I am entering:

Get-MailboxStatistics -Database “Mailbox Database” | Sort -Property TotalItemsize | Format-Table DisplayName, LastLoggedOnUserAccount, ItemCount, @{expression={$_.totalitemsize.value.ToMB()};label=”Size(MB)”}, LastLogonTime, LastLogoffTime | Export-CSV c:\mailboxes.csv

It displays correctly in the shell, but the output is distorted and looks like below attachment.

Any help would be appreciated.



mail.JPG
Avatar of craig_j_Lawrence
craig_j_Lawrence
Flag of Australia image

If you remove the format-table section, it should export to csv properly. As you have discovered, format-table is for on screen display, not for exporting to a file

Take a look at the 'one-liner' in the link, should guide you in the right direction: http://powershell.com/cs/media/p/1668.aspx

and this one show how to manipulate the data

http://aspoc.net/archives/2007/11/07/convert-the-get-mailboxstatistics-output-from-bytes-to-mb-or-gb-in-exchange-2007/

Hope this helps
Craig
Avatar of chadkline

ASKER

Thanks. I will try it out in the morning.
ASKER CERTIFIED SOLUTION
Avatar of sunnyc7
sunnyc7
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Please explain your solution sunnyc7
I just modified your script
sunnyc7,

Your output is exactly what I want, however, when I open the csv file, all of the columns are in one cell.
How can this be corrected?
Okay, here is what I did. I removed the Format Table and added Select:

Get-MailboxStatistics -Database “Mailbox Database” | Select DisplayName, LastLoggedOnUserAccount, ItemCount, @{expression={$_.totalitemsize.value.ToMB()};label=”Size(MB)”}, LastLogonTime, LastLogoffTime | Export-CSV c:\mailboxes2.csv

I got the results i wanted and in separate columns in the csv.
nice :)