Monday, July 11, 2011

Exchange 2010-Create a Mailbox Size Report

Here's my contribution. I wrote this script to include some additional information in the Mailbox size report:

Get-User -ResultSize Unlimited | Where {$_.RecipientType -eq "UserMailbox"} | Select DisplayName, Company, City | foreach {
$MailboxInfo = Get-Mailbox -identity $_.displayName
$MailboxStat = Get-MailboxStatistics -identity $_.displayName
Add-Member -InputObject $_ noteProperty UseDefault $MailboxInfo.UseDatabaseQuotaDefaults
Add-Member -InputObject $_ noteProperty WarningQuota $MailboxInfo.IssueWarningQuota
Add-Member -InputObject $_ noteProperty SendQuota $MailboxInfo.ProhibitSendQuota
Add-Member -InputObject $_ noteProperty SendRecieveQutoa $MailboxInfo.ProhibitSendReceiveQuota
Add-Member -InputObject $_ noteProperty MBAlias $MailboxInfo.Alias
Add-Member -InputObject $_ noteProperty QuotaStatus $MailboxStat.StorageLimitStatus
Add-Member -InputObject $_ noteProperty TotalItems $MailboxStat.ItemCount
Add-Member -InputObject $_ noteProperty TotalSizeMB $MailboxStat.TotalItemSize.Value.ToMB()
Add-Member -InputObject $_ noteProperty DeleteItems $MailboxStat.DeletedItemCount
Add-Member -InputObject $_ noteProperty DeletedSizeMB $MailboxStat.TotalDeletedItemSize.Value.ToMB() -PassThru
} | Export-Csv -Path D:\MailboxSize.csv


---------------------------------
Get-MailboxStatistics | Sort-Object TotalItemSize -Descending | ft DisplayName,@{label="TotalItemSize(MB)";expression={$_.TotalItemSize.Value.ToMB()}},ItemCount

This script will list all mailboxes starting with the largest then Descending down the page it will also give you number of items in each mailbox and list size in MB.
You can adjust the Size metric given by changing {$_.TotalItemSize.Value.ToMB()} to ether {$_.TotalItemSize.Value.ToKB()} or if you are unlucky {$_.TotalItemSize.Value.ToGB()}. Also if you would like to change the listing at the top of the report make a similar change to the "TotalItemSize(MB)" expression.

---------------------------------
When I run below command in Exchange Management Shell for Database name “Mailbox Database”, it gives similar output to ESM 2003. Only difference is it shows size in Bytes instead of KB.
Get-MailboxStatistics -database “Mailbox Database” | Select DisplayName, LastLoggedOnUserAccount, ItemCount, TotalItemSize, LastLogonTime, LastLogoffTime | Format-Table
 image
Now if I want to export this into CSV the I need to run below command.
Get-MailboxStatistics -Database “Mailbox Database” | Select DisplayName, LastLoggedOnUserAccount, ItemCount, TotalItemSize, LastLogonTime, LastLogoffTime | Export-CSV test.csv
image
Now lets say I want size in MB then I  need to run below command.
Get-MailboxStatistics -Database “Mailbox Database” | Format-Table DisplayName, LastLoggedOnUserAccount, ItemCount, @{expression={$_.totalitemsize.value.ToMB()};label=”Size(MB)”}, LastLogonTime, LastLogoffTime
image

If I want to sort this report by Mailbox Size then I need to run below command.
Get-MailboxStatistics -Database “Mailbox Database” | Sort -Property TotalItemsize | Format-Table DisplayName, LastLoggedOnUserAccount, ItemCount, @{expression={$_.totalitemsize.value.ToMB()};label=”Size(MB)”}, LastLogonTime, LastLogoffTime 
image
  • In these examples we got reports for database “Mailbox Database” in same way we can get it for whole server with below command.
      Get-MailboxStatistics -Server MailboxServer01
  • Here we added DisplayName, LastLoggedOnUserAccount, ItemCount, TotalItemSize, LastLogonTime, LastLogoffTime columns in our report and in same way we can add below list of columns …
AssociatedItemCount
Database
DatabaseName
DeletedItemCount
DisconnectDate
DisplayName
Identity
ItemCount
LastLoggedOnUserAccount
LastLogoffTime
LastLogonTime
LegacyDN
MailboxGuid
ServerName
StorageGroupName
StorageLimitStatus
TotalDeletedItemSize
TotalItemSize

1 comment: