ExchangeUsageHelper.psm1

function Get-LargeMailbox
{
    <#
            .Synopsis
            Gets large user mailboxes in an Exchange organization.
            .Description
            Retreives the largest Exchange mailboxes or the size of a specific user mailbox. Designed to be run in a remote Exchange Management Shell connection, not locally on an Exchange server.
            .Example
            Get-LargeMailbox -Top 25
            Gets the largest 25 mailboxes in the organization
            .Example
            Get-LargeMailbox -Identity Username
            Gets the size of Username's mailbox
            .Parameter Top
            The number of mailboxes to return
            .Parameter Identity
            The specific user to return
            .Inputs
            [string],[int]
            .Outputs
            [PSCustomObject]
            .Notes
            NAME: Get-LargeMailbox
            AUTHOR: Thomas Rayner
            LASTEDIT: 9/1/2015
            KEYWORDS:
            .Link
            http://workingsysadmin.com
            #Requires -Version 2.0
    #>

    [CmdletBinding()]
    param (
        [Parameter(Mandatory = $False,
                Position = 1,
        ValueFromPipeline = $True)]
        [int]$Top = 1,
        [Parameter(Mandatory = $False,
                Position = 1,
        ValueFromPipeline = $True)]
        [string]$Identity = '*'
    )
        
    Get-Mailbox -Identity $Identity -ResultSize Unlimited |
    Get-MailboxStatistics |
    Sort-Object -Property @{
        e = {
            $_.TotalItemSize.Value.ToString().split('(').split(' ')[-2].replace(',', '') -as [double]
        }
    } -Descending |
    Select-Object -Property DisplayName, @{
        l = 'MailboxSize'
        e = {
            $_.TotalItemSize.Value.ToString().split('(').split(' ')[-2].replace(',', '') -as [double]
        }
    } -First $Top
}

function Get-LargeFolder 
{
    <#
            .Synopsis
            Gets large folders within user mailboxes.
            .Description
            Retreives the largest Exchange mailbox folders for all users or a specific mailbox. Designed to be run in a remote Exchange Management Shell connection, not locally on an Exchange server.
            .Example
            Get-LargeFolder -Identity Username -Top 20
            Gets the largest 20 folders in Username's mailbox
            .Example
            Get-LargeFolder -FolderScope DeletedItems -Top 20
            Gets the largest 20 Deleted Items folders in the organization
            .Parameter Identity
            The username of a specific user whose mailbox is of interest
            .Parameter Top
            The number of results to return
            .Parameter FolderScope
            The scope of folders to look at - valid values are: 'All', 'Calendar', 'Contacts', 'ConversationHistory', 'DeletedItems', 'Drafts', 'Inbox', 'JunkEmail', 'Journal', 'LegacyArchiveJournals', 'ManagedCustomFolder', 'NonIpmRoot', 'Notes', 'Outbox', 'Personal', 'RecoverableItems', 'RssSubscriptions', 'SentItems', 'SyncIssues', 'Tasks'
            .Inputs
            [string],[int],[string]
            .Outputs
            [PSCustomObject]
            .Notes
            NAME: Get-LargeFolder
            AUTHOR: Thomas Rayner
            LASTEDIT: 9/1/2015
            KEYWORDS:
            .Link
            http://workingsysadmin.com
            #Requires -Version 2.0
    #>

    [CmdletBinding()]
    param (
        [Parameter(Mandatory = $False)]
        [ValidateSet('All', 'Calendar', 'Contacts', 'ConversationHistory', 'DeletedItems', 'Drafts', 'Inbox', 'JunkEmail', 'Journal', 'LegacyArchiveJournals', 'ManagedCustomFolder', 'NonIpmRoot', 'Notes', 'Outbox', 'Personal', 'RecoverableItems', 'RssSubscriptions', 'SentItems', 'SyncIssues', 'Tasks')]
        [string]$FolderScope = 'All',
        [Parameter(Mandatory = $False)]
        [int]$Top = 1,
        [Parameter(Mandatory = $False,
                Position = 1,
        ValueFromPipeline = $True)]
        [string]$Identity = '*'
    )

    Get-Mailbox -Identity $Identity -ResultSize Unlimited |
    Get-MailboxFolderStatistics -FolderScope $FolderScope |
    Sort-Object -Property @{
        e = {
            $_.FolderSize.split('(').split(' ')[-2].replace(',','') -as [double]
        }
    } -Descending |
    Select-Object -Property @{
        l = 'NameFolder'
        e = {
            $_.Identity.Split('/')[-1]
        }
    }, 
    @{
        l = 'FolderSize'
        e = {
            $_.FolderSize.split('(').split(' ')[-2].replace(',', '') -as [double]
        }
    } -First $Top
}

function Get-MailboxesPerDB
{
<#
  .Synopsis
    Gets the number of mailboxes on each Exchange DB.
   .Description
    Gets the number of mailboxes on each Exchange DB.
   .Example
    Get-MailboxesPerDB
    Gets the number of mailboxes on each Exchange DB
   .Inputs
    None
   .Outputs
    [PSCustomObject]
   .Notes
    NAME: Get-MailboxesPerDB
    AUTHOR: Thomas Rayner
    LASTEDIT: 9/1/2015
    KEYWORDS:
   .Link
     http://workingsysadmin.com
 #Requires -Version 2.0
 #>

    Get-Mailbox -ResultSize Unlimited |
    Group-Object -Property:Database |
    Select-Object -Property Name, Count |
    Sort-Object -Property:Name
}