Wednesday, May 18, 2011

View mailbox size on Exchange 2010

     Before showing how to view the mailbox size I'd like to make a quick note about scripts. Powershell commands can be put into a powershell script. Place the commands into a text file and save the file type as a .ps1 file. If you click on a powershell script, it will simply open in notepad. If you try to run it from inside powershell it will fail too. In order to run a powershell script from inside powershell you must first change the permissions. Use the command below to allow custom written scripts and any signed scripts you may have downloaded. View the link for more options.

Set permissions to run powershell scripts

       Set-ExecutionPolicy RemoteSigned
     The Get-MailboxStatistics command is used to display mailbox size. The instace displayed below shows the details for a single mailbox and displays the listed information for the mailbox in addition. 
 View mailbox Size:
Get-MailboxStatistics -identity username | ft DisplayName, TotalItemSize, ItemCount, StorageLimitStatus, Database
     This expounds on the previous command. If you place the following commands into a .PS1 script and run from inside powershell it will prompt you for the user name, display the size then ask if you would like to check another. A very simple example of how you can use scripts with these commands.
One User Script:
DO {
$name = read-host "Enter  username"
Get-MailboxStatistics -identity $name | ft DisplayName, TotalItemSize, ItemCount, StorageLimitStatus, Database
$ask = read-host "Check Another? (Y|N)"
}
WHILE ($ask -eq "Y")
     This command steps up from displaying a single mailbox to displaying every mailbox on the given server and sorts by mailbox size. This is followed by an example listing only the mailboxes for a given database. In addition you can limit the output to the first X number of results with the select-output command shown last. 
All Users 
Get-MailboxStatistics -server "mailserver1" | Sort-Object TotalItemSize -Descending | ft DisplayName, TotalItemSize, ItemCount, StorageLimitStatus, Database
Admin Database: 
Get-MailboxStatistics -Database "Admin" | Sort-Object TotalItemSize -Descending | ft DisplayName, TotalItemSize, ItemCount, StorageLimitStatus, Database
Top 10 mailboxes in the Admin Database my size: 
Get-MailboxStatistics -Database "Admin" | Sort-Object TotalItemSize -Descending | ft DisplayName, TotalItemSize, ItemCount, StorageLimitStatus, Database | Select-Object –first 10

No comments:

Post a Comment