Getting Exchange or Office 365 Mailbox Info with Get-MailBox

You can use the Exchange Admin Center (EAC) web interface or the Get-Mailbox PowerShell cmdlet to view mailbox information in your Office 365 tenant (Exchange Online) or on-prem Exchange organization. In this article, we’ll show you useful PowerShell commands with Get-Mailbox to get various information about Exchange mailboxes.

The Get-Mailbox cmdlet is available on the on-premises Exchange Server (2019/2016/2013/2010) organizations and the cloud-based Exchange Online service. Some of the parameters and attributes of the cmdlet may differ slightly depending on the Exchange version.

Let’s start by connecting to Exchange.

If you have on-premises Exchange Server, you can simply open the Exchange Management Shell (EMS) on a domain-joined computer or server. It will automatically connect to the nearest Exchange Server in your organization.

get mailbox

The Exchange Online PowerShell V2 module (EXO V2) is used to connect to Exchange Online tenant. The module can be installed on any computer from the PowerShell Gallery with the command:

Install-Module -Name ExchangeOnlineManagement

Connect to your Office 365 tenant:

Connect-ExchangeOnline -UserPrincipalName admin@theitbros.com

Log in with an Exchange Online administrator account using Modern Authentication.

get-mailbox command

To display information about a single mailbox, run the command:

Get-Mailbox -Identity AlexW@theitbros.com

Hint. One of the following parameters can be specified as Identity: Name,Display Name,Alias, Distinguished Name, Email Address, GUID, SamAccountName, Office 365 User ID, or User Principal Name.

The cmdlet will only display a few basic properties of the mailbox. To list all the available attributes of an Exchange mailbox, run:

Get-Mailbox -Identity AlexW@theitbros.com| Format-Table

get mailbox identity

Exchange mailbox has several dozens of different attributes. To display only certain attributes, the Select-Object cmdlet is used. For example, the following command will list the user’s UPN, SMTP address, mailbox creation date, user region, and mailbox type:

Get-Mailbox -Identity AlexW@theitbros.com | select-object UserPrincipalName, PrimarySMTPAddress, WhenMailboxCreated, UsageLocation, RecipientType

powershell get mailbox identity

You can display information about the quotas of a specific mailbox:

Get-Mailbox -Identity AlexW@theitbros.com | select *quota*

get mailbox quota powershell

To find out the size of the mailbox and the number of items in it, you need to use pipe with the Get-MailboxStatistics cmdlet:

Get-Mailbox -ResultSize Unlimited | Get-MailboxStatistics | select DisplayName,TotalItemSize, ItemCount

get mailbox statistics

Top 10 largest mailboxes:

Get-Mailbox | Get-MailboxStatistics | sort-object totalitemsize –descending | Select-Object displayname, totalitemsize ‑First 10

The following command will list inactive Office 365 mailboxes:

Get-Mailbox -InactiveMailboxOnly | Format-List Name,DistinguishedName,ExchangeGuid,PrimarySmtpAddress

Shared mailboxes:

Get-Mailbox –ResultSize Unlimited –RecipientTypeDetails SharedMailbox

Additional archive mailboxes:

Get-Mailbox –ResultSize Unlimited –Archive

You can also display the mailbox’s last logon time or last user activity time:

Get-Mailbox -ResultSize Unlimited |Foreach{

Get-MailboxStatistics -Identity $_.UserPrincipalName | Select DisplayName,LastLogonTime,LastUserActionTime}

get mailbox resultsize

List of mailboxes active in the last 30 days:

Get-Mailbox -ResultSize Unlimited –RecipientTypeDetails UserMailbox,SharedMailbox | Where {(Get-MailboxStatistics $_.Identity).LastLogonTime -gt (Get-Date).AddDays(-30)} | Sort -Property @{e={( Get-MailboxStatistics $_.Identity).LastLogonTime}} -Descending | Select-Object DisplayName,@{n="LastLogon";e={(Get-MailboxStatistics $_.Identity).LastLogonTime}}

get mailbox last logon

I enjoy technology and developing websites. Since 2012 I'm running a few of my own websites, and share useful content on gadgets, PC administration and website promotion.
Cyril Kardashevsky

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.