none
Exchange 2010 Mailbox Sizes and Attachment Sizes RRS feed

  • Question

  • I am needing to be able to produce a report weekly needing the following items to put out to a CSV file:

    Display Name

    Database

    Server

    total item count

    total mailbox size

    total sent item size

    plus the total space based on attachments in each mailbox

    The main reason I am needing this is because I have users with mailboxes over 30GB and some over 43GB.

    Thanks for any help!!


    Tuesday, June 11, 2013 8:34 PM

All replies

  • Found this script that gives all but the attachment sizing:
    <#
    .NOTES
    Written By: Paul Cunningham
    #>

    param(
     [Parameter(ParameterSetName='all')] [switch]$all,
     [string]$filename
    )

    #...................................
    # Variables
    #...................................

    $ErrorActionPreference = "SilentlyContinue"
    $WarningPreference = "SilentlyContinue"
    $report = @()


    #Set recipient scope
    $2007snapin = Get-PSSnapin -Name Microsoft.Exchange.Management.PowerShell.Admin
    if ($2007snapin)
    {
     $AdminSessionADSettings.ViewEntireForest = 1
    }
    else
    {
     $2010snapin = Get-PSSnapin -Name Microsoft.Exchange.Management.PowerShell.E2010
     if ($2010snapin)
     {
      Set-ADServerSettings -ViewEntireForest $true
     }
    }


    #If no filename specified, generate report file name with random strings for uniqueness
    #Thanks to @proxb and @chrisbrownie for the help with random string generation

    if ($filename)
    {
     $reportfile = $filename
    }
    else
    {
     $timestamp = Get-Date -UFormat %Y%m%d-%H%M
     $random = -join(48..57+65..90+97..122 | ForEach-Object {[char]$_} | Get-Random -Count 6)
     $reportfile = "MailboxReport-$timestamp-$random.csv"
    }
    #...................................
    # Script
    #...................................
    #Add dependencies
    Import-Module ActiveDirectory
    #Get the mailbox list
    Write-Host -ForegroundColor White "Collecting mailbox list"
    if($all) { $mailboxes = @(Get-Mailbox -resultsize unlimited -IgnoreDefaultScope) }
    #Get the report
    Write-Host -ForegroundColor White "Collecting report data"
    $mailboxcount = $mailboxes.count
    $i = 0
    #Loop through mailbox list and find the aged mailboxes
    foreach ($mb in $mailboxes)
    {
     $i = $i + 1
     $pct = $i/$mailboxcount * 100
     Write-Progress -Activity "Collecting mailbox details" -Status "Processing mailbox $i of $mailboxcount - $mb" -PercentComplete $pct

     $stats = $mb | Get-MailboxStatistics | Select-Object TotalItemSize,TotalDeletedItemSize,ItemCount,LastLogonTime,LastLoggedOnUserAccount
     $lastlogon = $stats.LastLogonTime

     #This is an aged mailbox, so we want some extra details about the account
     
     $user = Get-User $mb
     $aduser = Get-ADUser $mb.samaccountname -Properties Enabled,AccountExpirationDate

     #Create a custom PS object to aggregate the data we're interested in
     
     $userObj = New-Object PSObject
     $userObj | Add-Member NoteProperty -Name "DisplayName" -Value $mb.DisplayName
     $userObj | Add-Member NoteProperty -Name "Title" -Value $user.Title
     $userObj | Add-Member NoteProperty -Name "Department" -Value $user.Department
     $userObj | Add-Member NoteProperty -Name "Office" -Value $user.Office
     $userObj | Add-Member NoteProperty -Name "Enabled" -Value $aduser.Enabled
     $userObj | Add-Member NoteProperty -Name "Expires" -Value $aduser.AccountExpirationDate
     $userObj | Add-Member NoteProperty -Name "Last Mailbox Logon" -Value $lastlogon
     $userObj | Add-Member NoteProperty -Name "Last Logon By" -Value $stats.LastLoggedOnUserAccount
     $userObj | Add-Member NoteProperty -Name "Item Size (Mb)" -Value $stats.TotalItemSize.Value.ToMB()
     $userObj | Add-Member NoteProperty -Name "Deleted Item Size (Mb)" -Value $stats.TotalDeletedItemSize.Value.ToMB()
     $userObj | Add-Member NoteProperty -Name "Items" -Value $stats.ItemCount
     $userObj | Add-Member NoteProperty -Name "Type" -Value $mb.RecipientTypeDetails
     $userObj | Add-Member NoteProperty -Name "Server" -Value $mb.ServerName
     $userObj | Add-Member NoteProperty -Name "Database" -Value $mb.Database
     
     #Add the object to the report
     $report = $report += $userObj
    }

    #Catch zero item results
    $reportcount = $report.count

    if ($reportcount -eq 0)
    {
     Write-Host -ForegroundColor Yellow "No mailboxes were found matching that criteria."
    }
    else
    {
     #Output single mailbox report to console, otherwise output to CSV file
     if ($mailbox)
     {
      $report | Format-List
     }
     else
     {
      $report | Export-Csv -Path $reportfile -NoTypeInformation
      Write-Host -ForegroundColor White "Report written to $reportfile in current path."
      Get-Item $reportfile
     }
    }

    Tuesday, June 11, 2013 8:58 PM