«

»

Sep 09

Print this Post

Exchange 2013 Actual Mailbox Size Report

I wrote this script to collect all mailbox size information including the RecoverableItems folder info which is not included in Get-MailboxStatistics TotalItemSize. This will give a fuller picture of the storage used by each mailbox.

ActualMailboxSizeReport
ActualMailboxSizeReport
ActualMailboxSizeReport.ps1
Version: 1.0
3.5 KiB
112 Downloads
Details


### Load PS Modules needed to access Exchange PS CmdLets ###
Write-Host "Loading Exchange Management Powershell Modules"
Add-PSSnapin Microsoft.Exchange.Management.PowerShell.E2010, Microsoft.Exchange.Management.PowerShell.Setup , Microsoft.Exchange.Management.Powershell.Support

### Set this variable with the full export path for the CSV file ###
$outFile = “C:\temp\ActualMailboxSizeReport.csv”
### ###

### Load all mailboxes in the organization ###
$mbs = Get-Mailbox -ResultSize Unlimited

# Pull the MB Count
$count = $mbs.count

# $i will be used for a counter
$i = 0

# $outData will hold collected data until it is exported to CSV
$outData = @()

# Start the loop
foreach($mb in $mbs){
# Get the User Name for this mailbox
$mbName = $mb.Name

### This section provides a progress bar ###
$i += 1
$pctComplete = [int] (($i / $count) * 100)
Write-Progress -Activity “Collecting Data” -Status “($i / $count) – $mbName” -PercentComplete $pctComplete
### ###

### Get the RecoverableItems folder information for the user’s primary mailbox ###
$recStatsPri = $null
$recStatsPri = Get-MailboxFolderStatistics $mb.Name -FolderScope RecoverableItems | WHERE Identity -like “*Recoverable Items”
if($recStatsPri -eq $null){ $recStatsPri = 0}
else{ $recStatsPri = $recStatsPri.FolderAndSubfolderSize.ToMB() }
### ###

### Get the RecoverableItems folder information for the user’s archive mailbox ###
$recStatsArc = $null
$recStatsArc = Get-MailboxFolderStatistics $mb.Name -FolderScope RecoverableItems -Archive -ErrorAction SilentlyContinue -WarningAction SilentlyContinue | WHERE Identity -like “*Recoverable Items”
if($recStatsArc -eq $null){ $recStatsArc = 0}
else{ $recStatsArc = $recStatsArc.FolderAndSubfolderSize.ToMB() }
### ###

### Get the TotalItemSize for the primary mailbox ###
$priStats = $null
$priStats = Get-MailboxStatistics $mb.name
if($priStats -eq $null){ $priStats = 0}
else{ $priStats = $priStats.TotalItemSize.Value.ToMB() }
### ###

### Get the TotalItemSize for the archive mailbox ###
$arcStats = $null
$arcStats = Get-MailboxStatistics $mb.name -Archive -ErrorAction SilentlyContinue -WarningAction SilentlyContinue
if($arcStats -eq $null){ $arcStats = 0}
else{ $arcStats = $arcStats.TotalItemSize.Value.ToMB() }
### ###

### Assemble a hashtable of the collected information ###
$mbInfo = @{}
$mbInfo.Add(“Name”,$mb.name)
$mbInfo.Add(“OU”,$mb.OrganizationalUnit.Split(“/”)[($mb.OrganizationalUnit.Split(“/”).Count-1)])
$mbInfo.Add(“PrimaryDatabase”,$mb.Database)
$mbInfo.Add(“ArchiveDatabase”,$mb.ArchiveDatabase)

$mbInfo.Add(“PriItemSize”,$priStats)
$mbInfo.Add(“ArcItemSize”,$arcStats)
$mbInfo.Add(“PriRecoverable”,$recstatsPri)
$mbInfo.Add(“ArcRecoverable”,$recstatsArc)

$mbInfo.Add(“PriTotalSize”,$priStats + $recstatsArc)
$mbInfo.Add(“ArcTotalSize”,$arcStats + $recstatsArc)

$mbInfo.Add(“TotalSize”,$arcStats + $recstatsArc + $priStats + $recstatsArc)
### ###

### Convert the hashtable to a PSObject and add it to our data set ###
$outData += New-Object PSObject -Property $mbInfo
### ###
}

Write-Progress -Activity “Exporting Data” -Status “Complete” -Completed

### Export the data to a CSV file ###
$outData | SELECT Name,OU,PrimaryDatabase,ArchiveDatabase,PriItemSize,ArcItemSize,PriRecoverable,ArcRecoverable,PriTotalSize,ArcTotalSize,TotalSize | Export-Csv $outFile -NoTypeInformation

Permanent link to this article: https://www.wperry.net/exchange-2013/exchange-2013-actual-mailbox-size-report/

Leave a Reply

Your email address will not be published. Required fields are marked *