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.
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.
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
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
You can display information about the quotas of a specific mailbox:
Get-Mailbox -Identity AlexW@theitbros.com | select *quota*
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
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}
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}}
- Using Nslookup in Windows to List DNS Servers and Records - May 11, 2022
- Fix: Windows 10 Keyboard not Working - May 11, 2022
- How to Fix Gmail Not Updating on iPhone? - May 3, 2022