Skip to content

Get-ExchangeMailbox

Exchange: Lists all mailboxes in the organization

#Requires -Version 5.1

[CmdletBinding()]
Param (
    [string]$Filter,

    [string]$ResultSize = 'Unlimited'
)

Process {
    try {
        $params = @{
            'ResultSize'  = $ResultSize
            'ErrorAction' = 'Stop'
        }
        if ($Filter) { $params.Add('Filter', $Filter) }

        $mailboxes = Get-Mailbox @params

        $results = foreach ($mb in $mailboxes) {
            [PSCustomObject]@{
                DisplayName          = $mb.DisplayName
                Alias                = $mb.Alias
                PrimarySmtpAddress   = $mb.PrimarySmtpAddress
                RecipientTypeDetails = $mb.RecipientTypeDetails
                Database             = $mb.Database.Name
                IsResource           = $mb.IsResource
                LastModified         = $mb.WhenChanged
            }
        }

        Write-Output ($results | Sort-Object DisplayName)
    }
    catch {
        throw
    }
}

Optional. Specifies an OPATH filter to apply to the retrieval.

Optional. Specifies the maximum number of results to return. Defaults to Unlimited.

An interactive directory of PowerShell scripts.