Getting Exchange or Office 365 Mailbox Info with Get-MailBox

You may simply launch the Exchange Management Shell (EMS) on a domain-joined PC or server if you have an on-premises Exchange Server. It will connect to the closest Exchange Server in your business automatically. To connect to an Exchange Online tenancy, utilize the Exchange Online PowerShell V2 module (EXO V2). The module may be downloaded from the PowerShell Gallery and installed on any machine with the command:

Install-Module -Name ExchangeOnlineManagement

Connect to your Office 365 tenant:

Connect-ExchangeOnline -UserPrincipalName

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

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

Get-Mailbox -Identity

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| Format-Table

There are thousands of distinct properties in an Exchange mailbox. The Select-Object cmdlet is used to display just particular characteristics. The user’s UPN, SMTP address, mailbox creation date, user region, and mailbox type, for example, maybe found with the following command:

Get-Mailbox -Identity | select-object UserPrincipalName, PrimarySMTPAddress, WhenMailboxCreated, UsageLocation, RecipientType

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

Get-Mailbox -Identity | 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}}

Leave a Reply

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

Enter Captcha Here :