I got a question form a friend if I could help and sort out a command that exported mailbox size and quotas to a CSV file for him. This should work for both Exchange Server 2007 and 2010, here is how we did it:
First run a get mailbox command:
Get-Mailbox -ResultSize Unlimited
Then we add a pipe and a number of attributes we want to get:
Get-Mailbox -ResultSize Unlimited | Select-Object DisplayName, IssueWarningQuota, ProhibitSendQuota
We continue with adding two that performs Get-MailboxStatistics to receive attributes from the mailbox that the Get-Mailbox Cmdlet does not give us:
@{label=”TotalItemSize(MB)”;expression={(Get-MailboxStatistics $_).TotalItemSize.Value.ToMB()}} and @{label=”ItemCount”;expression={(Get-MailboxStatistics $_).ItemCount}}
Then we add another attribute that Get-Mailbox gives us:
Database
And to finish it off we export the results to a CSV file after another pipe:
| Export-Csv “UserMailboxSizes.csv” –NoTypeInformation
And the complete command again with all parts combined together:
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
This command can of course be modified and you can add other attributes or functions. In the following example I use where to get only the mailboxes that does not use the database default quota.
Where {$_.UseDatabaseQuotaDefaults -eq $false
And the complete command:
Get-Mailbox -ResultSize Unlimited | Where {$_.UseDatabaseQuotaDefaults -eq $false} | 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
There you go, enjoy and do not hesitate to let me know if you have any questions!