Exchange 2010 Archive Mailbox Statistics PowerShell script

/

Here are some field notes from a recent Exchange 2010 Retention and Archive case.

I have made a simple Exchange 2010 PowerShell script Get-ArchivedMBStats.ps1, that shows mailbox statistics for all mailboxes that have Online Archive enabled. It is great for following the progress of archiving of individual mailboxes.

The output of the script is the following information about each mailbox with archive enabled:

  • Mailbox Display Name
  • Mailbox TotalItemSize (MB)
  • Mailbox ItemCount
  • Mailbox Database
  • Mailbox RetentionPolicy
  • Archive Display Name
  • Archive TotalItemSize (MB)
  • Archive ItemCount
  • Archive Database
      The output is show as:

    Display Name    TotalItemSize (MB)   ItemCount    Database      RetentionPolicy
    ————    —————–    ———    ——–      —————
    Peter Schmidt                 147         3572      EXDB01    Default Archive..
    Online Archive – Pet…       430         4798      ARDB01

Here is the code (download as zip at the end of the article):

###########################################################################
#
# NAME: Get-ArchivedMBStats.ps1
#
# AUTHOR: Peter Schmidt
# EMAIL: [email protected]
#
# COMMENT: Shows all mailboxes that are enabled for Online Archvie in Exchange 2010. Output shows both Mailbox and Archived Mailbox statistics.
#
# You have a royalty-free right to use, modify, reproduce, and
# distribute this script file in any way you find useful, provided that
# you agree that the creator, owner above has no warranty, obligations,
# or liability for such use.
#
# VERSION HISTORY:
# 1.0 2011.09.29 - Initial release
#
# OUTPUT EXAMPLE:
#	Display Name                 TotalItemSize (MB)               ItemCount Database                RetentionPolicy
#	------------                 ------------------               --------- --------                ---------------
#	Peter Schmidt                               147                    3572 EXDB01                  Default Archive and ...
#	Online Archive - Pet...                     430                    4798 ARDB01
#
# HOW TO RUN:
#	.Get-ArchivedMBStats.ps1 | ft
#
# INPUTS:
#	None. You cannot pipe objects to this script.
#
###########################################################################

$combCollection = @()

Write-Host "`nPlease wait...`n"

$archiveMailboxes = Get-Mailbox | where {$_.ArchiveDatabase -ne $null} | Select Identity, RetentionPolicy

ForEach ($mbx in $archiveMailboxes)
{
	$mbxStats = Get-MailboxStatistics $mbx.Identity | Select DisplayName, TotalItemSize, ItemCount, Database
	$archiveStats = Get-MailboxStatistics $mbx.Identity -Archive | Select DisplayName, TotalItemSize, ItemCount, Database

	$mbcomb = "" | Select "Display Name", "TotalItemSize (MB)", ItemCount, Database, RetentionPolicy
	$archcomb = "" | Select "Display Name", "TotalItemSize (MB)", ItemCount, Database

	$mbcomb."Display Name" = $mbxStats.DisplayName
	$mbcomb."TotalItemSize (MB)" = [math]::round($mbxStats.TotalItemSize.Value.ToMB(), 2)
	$mbcomb.ItemCount = $mbxStats.ItemCount
	$mbcomb.Database = $mbxStats.Database
	$mbcomb.RetentionPolicy = $mbx.RetentionPolicy
	$archcomb."Display Name" = $archiveStats.DisplayName
	$archcomb."TotalItemSize (MB)" = [math]::round($archiveStats.TotalItemSize.Value.ToMB(), 2)
	$archcomb.ItemCount = $archiveStats.ItemCount
	$archcomb.Database = $archiveStats.Database

	$combCollection += $mbcomb
	$combCollection += $archcomb
	$combCollection += "`n"
}
write-output $combCollection
Write-Host "`nList of archived mailboxes done...`n" -Foregroundcolor Green

Download script here: https://gallery.technet.microsoft.com/Get-basic-statistics-of-b35fff8a

(Redirect to TechNet Gallery)

 

Hope you like the script

/Enjoy

+Peter Schmidt

22 thoughts on “Exchange 2010 Archive Mailbox Statistics PowerShell script”

  1. can you be more select on what server to run this script on?  I don't want to run the script at the organization level, just site level…

  2. I have tried using the script and i get the following errors

    Cannot bind argument with parameter identity because it is a null
    You can’t call a method on a null-valued expression.

    This script is exactly what i needed but its rendering no output for me. Any help would be appreciated. BTW Great Job on the Script!!

    THANKS

  3. My question is, can I schedule this in Task scheduler to send out a report via .html? If so what how do I add the syntax in task scheduler to accommodate the out-file?

  4. (Ignore my previous comment please, script had a fault in it)

    Made a modified version that’s easier to export to CSV (one line per user) and just holds the username / size / databasenames:

    ###########################################################################
    #
    # NAME: Get-ArchivedMBStats.ps1
    #
    # AUTHOR: Peter Schmidt / Niels Wijnja
    # EMAIL: [email protected] / [email protected]
    #
    # COMMENT: Shows all mailboxes that are enabled for Online Archvie in Exchange 2010. Output shows both Mailbox and Archived Mailbox statistics.
    #
    # You have a royalty-free right to use, modify, reproduce, and
    # distribute this script file in any way you find useful, provided that
    # you agree that the creator, owner above has no warranty, obligations,
    # or liability for such use.
    #
    # VERSION HISTORY:
    # 1.0 2011.09.29 – Initial release
    # 1.1 2014.03.07 – Modified version best suitable for Export-CSV
    #
    # OUTPUT EXAMPLE:
    # Identity Size (MB) Database ArchiveSize (MB) ArchiveDatabase
    # ———— ————– ——– —————- —————
    # domain.extUsersPeter.Schmidt 147 EXDB01 555 EXARCHDB01
    #
    # HOW TO RUN:
    # .Get-MailboxSizes.ps1 | ft
    # .Get-MailboxSizes.ps1 | Export-CSV MailboxSizes.csv
    #
    # INPUTS:
    # None. You cannot pipe objects to this script.
    #
    ###########################################################################

    $combCollection = @()

    Write-Host “`nPlease wait…`n”

    $archiveMailboxes = Get-Mailbox -resultsize 100000 | where {$_.ArchiveDatabase -ne $null} | Select Identity, RetentionPolicy

    ForEach ($mbx in $archiveMailboxes)
    {

    $mbxStats = Get-MailboxStatistics $mbx.Identity | Select DisplayName, TotalItemSize, ItemCount, Database
    $archiveStats = Get-MailboxStatistics $mbx.Identity -Archive | Select DisplayName, TotalItemSize, ItemCount, Database

    $mbcomb = “” | Select Identity, “Size (MB)”, Database, “ArchiveSize (MB)”,ArchiveDatabase

    $mbcomb.Identity = $mbx.Identity
    $mbcomb.”Size (MB)” = [math]::round($mbxStats.TotalItemSize.Value.ToMB(), 2)
    $mbcomb.Database = $mbxStats.Database
    $mbcomb.”ArchiveSize (MB)” = [math]::round($archiveStats.TotalItemSize.Value.ToMB(), 2)
    $mbcomb.ArchiveDatabase = $archiveStats.Database

    $combCollection += $mbcomb
    # $combCollection += $archcomb
    # $combCollection += “`n”
    }
    write-output $combCollection
    Write-Host “`nList of archived mailboxes done…`n” -Foregroundcolor Green

  5. Does this work for users with their primary mailbox on prem and their online archive on o365 in a hybrid configuration?

    • Not without modification, since the script then need to connect to Exchange Online.
      But if connected to Exchange Online, it should be possible to make such a report. Possible with minor modifications.

      • in the current script where it is mentioned about the output file as .csv

        after running this script I need to get output .
        kindly provide details .

  6. Can you provide me the modifications in the script, so that I can run it for Hybrid environment to fetch the data. We have on-prem mailboxes and archives on cloud. By the way the script is awesome but unfortunately cannot suffice our requirement.

  7. Great script….just one thing I was hoping to incorporate the following section

    $AccEnabled = Get-ADUser -Identity $mailbox.SamAccountName

    $mbcomb.Enabled = $AccEnabled.Enabled

    I’ve got the following snippet from a different script which retrieves the status of the AD account but when I’ve tried to incorporate it into this script I get the error shown at end of line

    Error on console session.

    get-ADUser : Cannot validate argument on parameter ‘Identity’. The argument is null or an element of the argument collection contains a null value.

Comments are closed.