Generate report of  user mailbox size for Exchange 2010

Introduction

This script could be used to export mailboxes’ information to a CSV file, including SamAccountName, DisplayName, TotalItemSize. Based on these CSV files, script will also generate a report about the variation tendency of usermailbox.

Scenarios

IT Administrators may care about the size of user’s mailbox.  It’s good for admins to log this size information every day, and create report when admins want to check the variation tendency of usermailbox.

Script

This script has six parameters:

ExportMailboxSize: If specified, this script will generate a CSV file about current mailbox's size of users. The CSV file will locate in “c:\log” by default, unless you specified the path by parameter -LogPath.

CompareMailboxSize: If specified, this script will generate a report depends on CSV files, which created by parameter -ExportMailboxSize. These CSV files were located in “c:\log” by default. If not, please indicate the path by parameter -LogPath.

LogPath: Indicate the path of CSV files, which are necessary to this script. It’s an optional parameter and “c:\log” will be the default value.

Identity: This parameter could be only used, parameter -ExportMailboxSize was specified. Identity indicates which usermailbox’s information should be export to CSV file. It’s an optional parameter, all usermailbox will be export to CSV file, if parameter not specified.

StartDate: This parameter could be only used, parameter - CompareMailboxSize was specified. The StartDate parameter specifies the first date you want to see in report. Any kind of date format is allowed. eg: “7/13/2012”, “2012-7-13”.

EndDate: This parameter could be only used, parameter - CompareMailboxSize was specified. The EndDate parameter specifies the last date you want to see in report. Any kind of date format is allowed. eg: “7/13/2012”, “2012-7-13”.

You could both run this script manually, or by scheduler task

How to run script manually:

   1. Open Exchange Management Shell in “Run as Administrator” mode.

   2. Switch to the path, where you download the script.

   3. Run the script as example command below.

How to create a scheduler task:

  1. Open “Task Scheduler” from control panel.

  2. Click “Create task”

  3. Pick a name, and choose “Run whether user is logged on or not”

   4. Choose “Triggers” Tab, Click “New”

   5. Specify option you like, then Click “OK” to create a trigger

  6. Choose “Actions” tab, Click “New”

  7. Copy following command to “Program/script” textbox, then replace the Bold words with example commands, and click “OK”

C:\Windows\System32\WindowsPowerShell\v1.0\powershell.exe -noexit -command ". 'C:\Program Files\Microsoft\Exchange Server\V14\bin\RemoteExchange.ps1'; Connect-ExchangeServer –auto; .\C:\CompareOSCmailboxstatistcs.ps1 -ExportMailboxSize"

Note      Scripting with the Exchange Management Shell

  8. Click “OK”. Till now task was created.

Here are some code snippets for your references. To get the complete script sample, please click the download button at the beginning of this page.

PowerShell
Edit|Remove
if (-not ($Identity)) 
    { 
        $UserMailboxs=Get-Mailbox -Filter'RecipientTypeDetails -eq "UserMailbox"'-ResultSize unlimited  
    } 
    else 
    { 
        $UserMailboxs=$Identity|Get-Mailbox -Filter'RecipientTypeDetails -eq "UserMailbox"'-ResultSize unlimited 
    }

Examples 

Example 01How to generate a CSV file, which contains specified user’s current mailbox size

To generate a CSV file, run the following command:

                .\CompareOSCmailboxstatistcs.ps1 -ExportMailboxSize -Identity “edward”,”david”

 

Example 02How to generate a CSV file to path “C:\EXlog”, including all users’ mailbox size.

To generate a CSV file, run the following command:

.\CompareOSCmailboxstatistcs.ps1 -ExportMailboxSize -LogPath “C:\EXlog” 


Example 03: How to compare mailbox size trend during a specific period, and generate a report.

To compare mailbox size, and generate a report, run the following command:

.\CompareOSCmailboxstatistcs.ps1 –CompareMailboxSize -StartDate "2012/7/3" -EndDate "2012-7-6”


Note: The name of these CSV files should never be modified.

 

Additional Resources

Technical Resources:

Windows PowerShell Advanced Function

http://technet.microsoft.com/en-us/library/dd315326.aspx

Get-Mailbox

http://technet.microsoft.com/en-us/library/bb123685

Get-MailboxStatistics

http://technet.microsoft.com/en-us/library/bb124612.aspx

Import-CSV

http://technet.microsoft.com/en-us/library/hh849891.aspx

Export-CSV

http://technet.microsoft.com/en-us/library/hh849932 

Scripting with the Exchange Management Shell

http://technet.microsoft.com/library/94c22e59-7460-4563-af20-79544c2bc2ff.aspx