Friday, 5 June 2015

Get Mailbox Size for All Users using PowerShell

We can find the total used space of mailbox of all users by using the exchange powershell cmdlet Get-MailboxStatistics. The Get-MailboxStatistics cmdlet is used to obtain information about a mailbox, such as the total size of the mailbox, the number of messages it contains, and the mailbox logon activity.

Summary:

Get Mailbox Size for Single User:

Get-MailboxStatistics -Identity 'Kevin' | Select DisplayName,ItemCount,TotalItemSize
Note: If you are working with normal PowerShell console instead of Exchange Management Shell, you need to run the following command to import exchange management powershell cmdlets.
Add-PSSnapin Microsoft.Exchange.Management.PowerShell.E2010

Get Mailbox Size for All Users:

To get malibox size of all the users, you need to give exchange server name as input paramater instead of user identity .Use the below powershell script to get mailbox size of all the users.
Get-MailboxStatistics -Server 'ExchSVR1' | Where {$_.ObjectClass -eq “Mailbox”} | 
Select-Object -Property @{label=”User”;expression={$_.DisplayName}},
@{label=”Total Messages”;expression= {$_.ItemCount}},
@{label=”Total Size (MB)”;expression={$_.TotalItemSize.Value.ToMB()}}, LastLogonTime

Get a list of Mailboxes sorted by size:

The following powershell script get a list of mailboxes with sizes and sorted by size in Descending order, so that you can easily find the users who are using high storage space in their mailbox.
Get-MailboxStatistics -Server 'ExchSVR1' | Where {$_.ObjectClass -eq “Mailbox”} | 
Sort-Object TotalItemSize -Descending |
Select-Object -Property @{label=”User”;expression={$_.DisplayName}},
@{label=”Total Messages”;expression={$_.ItemCount}},
@{label=”Total Size (MB)”;expression={$_.TotalItemSize.Value.ToMB()}}, 
LastLogonTime

Export Mailbox Size Report to CSV:

We can export powershell output into CSV file using Export-CSV cmdlet. The following powershell script export all the user's mailbox size, total messages and lastLogon time values into CSV file.
Get-MailboxStatistics -Server 'ExchSVR1' | Where {$_.ObjectClass -eq “Mailbox”} | 
Select-Object -Property @{label=”User”;expression={$_.DisplayName}},
@{label=”Total Messages”;expression={$_.ItemCount}},
@{label=”Total Size (MB)”;expression={$_.TotalItemSize.Value.ToMB()}}, LastLogonTime | 
Export-CSV "C:\\MailBoxSize-Report.csv" -NoTypeInformation -Encoding UTF8

CSV output of mailbox size report:

Exchange Powershell - Get Mailbox Size for All Users

Get Mailbox Size of specific set of users:

You can use the exchange management powershell cmdlet Get-Mailbox to get specific set of mailbox enabled Active Directory users and pass user details to Get-MailboxStatistics cmdlet. You can apply filters in Get-Mailbox cmdlet to select users.
Get-Mailbox | Where {$_.DistinguishedName -like "*OU=TestOU,DC=TestDomain,DC=local*"} |
Get-MailboxStatistics | Where {$_.ObjectClass -eq “Mailbox”} | 
Select-Object -Property @{label=”User”;expression={$_.DisplayName}},
@{label=”Total Messages”;expression={$_.ItemCount}},
@{label=”Total Size (MB)”;expression={$_.TotalItemSize.Value.ToMB()}}, LastLogonTime

Advertisements
Advertisements

No comments:

Post a Comment