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: peter@msdigest.net
#
# 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:

Get-ArchiveMBStats (52.0 KiB, 1082 downloads)

Redirect to TechNet Gallery.

  • Pingback: Exchange 2010 Archive Mailbox Statistics PowerShell script - Peter Schmidt - IT-experts.dk()

  • Pingback: msdigest.net » How to copy Online Archive data back into the mailbox()

  • Jirawat

    Thank you very much for sharing a very useful script.

  • NLCribby

    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…

  • http://www.msdigest.net Peter Schmidt

    Hi, you can run it on any server, but in your case, I would run it on the MBX server then.

  • adokilla

    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

  • http://Exchange2010ArchiveMailboxStatisticsPowerShellscript Kurt Rey

    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?

  • josh

    Is there way to pipe the output to csv or html file

  • Niels Wijnja

    (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: peter@msdigest.net / niels.wijnja@kpn.com
    #
    # 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.ext\Users\Peter.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

  • http://www.benway.net JasonB

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

    • Peter Schmidt

      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.

Share with your friends










Submit