Exchange Shell Script to Output Mailbox Sizes for All Users
The following script outputs all mailbox names and their size in MB to a flat file (c:\sizes.txt). You can copy and paste this script into exchange management shell to output all of the sizes of your mailboxes to a text file for your review. The script also sums up all of the mailbox sizes and outputs an average.
#——–begin script——–
del C:\sizes.txt
$totalsize=0
$totalusers=0
$databases = get-mailboxdatabase
foreach ($database in $databases)
{
$mailboxes = get-mailbox -database $database
foreach ($mailbox in $mailboxes)
{
$user = get-mailboxstatistics $mailbox.name
$user = [string]$user.totalitemsize
$user = $user.Replace(”B”,”")
$user = [int]$user
$totalsize = $totalsize + $user
$totalusers = $totalusers + 1
$user = $user / 1024
$user = $user / 1024
$mailbox.name | out-file c:\sizes.txt -append | out-null
$user = [math]::round($user, 2)
$user = [string]$user
$user = $user + ” MB”
$user | out-file c:\sizes.txt -append | out-null
}
}
$totalsize = $totalsize / 1024
$totalsize = $totalsize / 1024
$totalsize = [math]::round($totalsize, 2)
$newline = “`n” | out-file c:\sizes.txt -append | out-null
$totalmailboxsize = “Total size of all mailboxes: $totalsize MB”
$totalmailboxsize | out-file c:\sizes.txt -append | out-null
$totalnumbermailboxes = “Total number of mailboxes is: $totalusers”
$totalnumbermailboxes | out-file c:\sizes.txt -append | out-null
$average = $totalsize / $totalusers
$average = [math]::round($average, 2)
$averagesize = “The average is: $average MB”
$averagesize | out-file c:\sizes.txt -append | out-null
#———————End Script—————–
Tags: none
Leave a Reply