One of the most used PowerShell commands used by Exchange administrators is the Get-Mailbox cmdlet. This cmdlet has been available since Exchange Server 2007 and up to the latest version (2019 as of this writing) and Exchange Online.
The Get-Mailbox cmdlet’s purpose is simple—retrieve information about mailboxes in your Exchange organization. In this article, we’ll show several practical examples of using Get-Mailbox to get information about Exchange mailboxes.
Table of Contents
Get Information on a Specific Mailbox
Exchange administrators often view the information of one mailbox at a time using the Exchange Admin Center.
You can get the information using the Get-Mailbox cmdlet by specifying the mailbox identity.
Get-Mailbox -Identity <mailbox identity>
The -Identity parameter accepts the following mailbox identifiers.
- Name
- Alias
- Distinguished name (DN)
- Canonical DN
- Domain
- Email address
- GUID
- LegacyExchangeDN
- SamAccountName
- User ID or user principal name (UPN)
Default Property Set
As you can see below, the default property set the Get-Mailbox cmdlet returns include the Name, Alias, ServerName, and ProhibitSendQuota.
Running the same command in Exchange Online PowerShell returns a different property set that includes the Name, Alias, Database, ProhibitSendQuota, and ExternalDirectoryObjectId.
But you can find all Get-Mailbox properties by piping the resultant mailbox object to the Get-Member cmdlet.
Get-Mailbox -Identity <mailbox identity> | Get-Member -MemberType Properties
Get All Mailbox
Running the Get-Mailbox cmdlet without parameters returns up to 1000 mailboxes.
$mailboxCollection = Get-Mailbox $mailboxCollection.Count
But this limit can be adjusted by adding the -ResultSize parameter. This parameter accepts a number to indicate how many mailboxes to return. For example, the command below returns a maximum of 5000 mailboxes.
$mailboxCollection = Get-Mailbox -ResultSize 5000 $mailboxCollection.Count
The -ResultSize parameter also accepts the word Unlimited, which indicates to return all mailboxes.
$mailboxCollection = Get-Mailbox -ResultSize Unlimited $mailboxCollection.Count
Get Mailbox in a Specific Database
Another typical Get-Mailbox usage is finding which mailboxes are in a specific database. Note that this usage applies only to Exchange Servers and not to Exchange Online.
For example, the command below gets the mailboxes in the DB02 mailbox database.
Get-Mailbox -Database DB02 | Format-Table DisplayName,ServerName,Database
Get Mailbox of a Specific Type
When running the Get-Mailbox cmdlet, you can also get specific mailbox types using the RecipientTypeDetails parameter. This parameter accepts one or more mailbox types from this list:
- DiscoveryMailbox
- EquipmentMailbox
- GroupMailbox (Exchange 2013 or later and Exchange Online)
- LegacyMailbox
- LinkedMailbox
- LinkedRoomMailbox (Exchange 2013 or later and Exchange Online)
- RoomMailbox
- SchedulingMailbox (Exchange 2016 or later and Exchange Online)
- SharedMailbox
- TeamMailbox (Exchange 2013 or later and Exchange Online)
- UserMailbox
The example command below lists the SharedMailbox and RoomMailbox mailbox types.
Get-Mailbox -RecipientTypeDetails SharedMailbox,RoomMailbox | Format-Table DisplayName,RecipientTypeDetails
Get Mailbox Filtered by Attributes
The Get-Mailbox cmdlet has a -Filter parameter that lets you filter the mailbox objects to return by their attributes. You can filter mailboxes based on properties like Alias, PrimarySMTPAddress, City, Company, etc.
You can find a comprehensive list of filterable properties at Filterable properties for the Filter parameter on Exchange cmdlets.
For example, the below command filters mailboxes whose Alias property value starts with Jo.
Get-Mailbox -Filter "Alias -like 'Jo*'"
Note that not all properties support wildcard (*) character comparison. But if they do, the wildcard character comparison is supported as a suffix (word*) and not a prefix (*word). Even if a prefix wildcard worked in some instances, Microsoft does not recommend it due to low-performance issues.
Another example is listing mailboxes on litigation hold. This example filters mailboxes whose LitigationHoldEnabled property is set to True. Below are four variations of this filtering example that perform the same comparison operation.
Get-Mailbox -Filter 'LitigationHoldEnabled -eq $true' | Format-Table DisplayName, LitigationHoldEnabled Get-Mailbox -Filter "LitigationHoldEnabled -eq `$true" | Format-Table DisplayName, LitigationHoldEnabled Get-Mailbox -Filter { LitigationHoldEnabled -eq $true } | Format-Table DisplayName, LitigationHoldEnabled Get-Mailbox -Filter { LitigationHoldEnabled -eq 'true' } | Format-Table DisplayName, LitigationHoldEnabled
Get Mailbox Sorted by Size
The mailbox size property is not included in the mailbox object returned by Get-Mailbox. You can get the TotalItemSize using the Get-MailboxStatistics cmdlet instead.
Typically, you can pipe the Get-Mailbox results to Get-MailboxStatistics like so:
Get-Mailbox | Get-MailboxStatistics
However, if the mailbox identity is ambiguous (not unique), you’ll get an error similar to this:
Get-MailboxStatistics: Ex838C9A|Microsoft.Exchange.Configuration.Tasks.ManagementObjectAmbiguousException | The specified mailbox Identity:“mailbox” isn’t unique.
To avoid getting that error, it’s better to process each mailbox through a loop, like the ForEach-Object Loop, and specify each unique mailbox identity.
I’ll use the primary SMTP address as the unique mailbox identifier in this example. The result is shown in descending order by TotalMailboxSize.
Get-Mailbox -RecipientTypeDetails UserMailbox | ForEach-Object { Get-MailboxStatistics $_.PrimarySmtpAddress.ToString() } | Sort-Object TotalItemSize -Descending | Select-Object DisplayName, TotalItemSize
Related. How to generate Office 365 mailbox size report using PowerShell?
Get Mailbox Last Logged On Information
Finding out which mailboxes have been inactive is one way to help with housekeeping. Building upon the previous example, we can pipe the Get-Mailbox results to Get-MailboxStatistics to determine when the mailboxes were accessed and calculate how many days since.
Get-Mailbox -RecipientTypeDetails UserMailbox | ForEach-Object { Get-MailboxStatistics $_.PrimarySmtpAddress.ToString() } | Sort-Object LastLogonTime -Descending | Select-Object DisplayName, LastLogonTime, @{ n="DaysSinceLastLogOn";e={(New-TimeSpan -Start $_.LastLogonTime -End (Get-Date)).Days} }
The output is sorted by LastLogonTime, starting from the most recent.
Related. How to send Office 365 password expiration notification.
Get Mailbox with Full Access Permissions
If you’re wondering which of your users has full access to other mailboxes, you can pipe the Get-Mailbox results to the Get-MailboxPermission cmdlet.
$fullAccessPermission = Get-Mailbox -ResultSize Unlimited | ForEach-Object { Get-MailboxPermission -Identity $_.PrimarySmtpAddress.ToString() } | Where-Object { $_.AccessRights -Contains "FullAccess" } $fullAccessPermission | Format-Table Identity, User
PowerShell Script to Get Mailbox Storage Quota Status
In pre-Exchange Server 2013, the Information Store caches the StorageLimitStatus property that determines whether the mailbox storage usage (quota) status is normal, warning, sending disabled, and send/receive disabled.
There’s no straightforward method to get the mailbox storage quota status beginning in Exchange 2013 and Exchange Online. Lucky for you, we’ve created a PowerShell function that you can conveniently use to report the mailbox quota status.
You can get the script from this repository →: GetMailboxQuotaStatus. Import the function into your PowerShell session by dot-sourcing or pasting the code directly.
Get the Quota Status of All Mailboxes
To get the quota status of all mailboxes, run this command.
Get-Mailbox -ResultSize Unlimited | Get-QuotaStatus
Get the Quota Status of One or More Mailboxes
This example gets the mailbox quota status of one mailbox.
# Using the pipeline input Get-Mailbox <identity> | Get-QuotaStatus # Using the parameter input Get-QuotaStatus -Mailbox (Get-Mailbox <identity>) Get-QuotaStatus -Mailbox <email@domain.com>,<Alias>,<SamAccountName>
Conclusion
The Get-Mailbox cmdlet is an indispensable tool in an Exchange Administrator toolbox. It may be a simple command, but it can be used to get basic and complex information about Exchange Server or Exchange Online mailboxes.