Want to export all mailboxes from Exchange? Or need to look up the mailbox settings from a particular user? With the cmdlet Get-Mailbox in PowerShell, we can quickly extract all information that we need from the Exchange Online server.
You can find pretty much all mailbox information in the Exchange Admin center, but as you might have noticed, this isn’t always the fastest way to look up information. Especially when you want to get or export mailbox information from multiple users, then you will need to use PowerShell.
In this article
In this article, we are going to take a look at how to use the Get-Mailbox cmdlet in PowerShell. I will give some useful examples when it comes to finding and exporting mailbox information. And as a bonus, I have added a complete script to the most important information from your mailboxes.
Install the Exchange Online Module
Before we can use the Get-Mailbox cmdlet in PowerShell you will need to install the Exchange Online module. Make sure that you install the latest Exchange Online v3 Module, which you can use on PowerShell 5 and 7.
Note
TheGet-Mailbox
cmdlet can also be used on an on-premise Exchange Server version 2010 and higher, but for the on-premise version you will need to use the Exchange Management Shell
In this article, I will focus on the Exchange Online server. Make sure that you are connected to Exchange Online:
Connect-ExchangeOnline -UserPrincipalName [email protected]
Finding Mailboxes with Get Mailbox in PowerShell
The Get Mailbox cmdlet allows us to find mailboxes from the Exchange Online server and extract information from them. The advantage of the cmdlet is that we can use different options to find or filter the mailboxes.
We can use the following options to find mailboxes:
- Anr – Find a mailbox by part of the name (ambiguous name resolution)
- Identity – Find mailbox based on the name, user domain name, or email address
- Filter – Retrieve multiple mailboxes based on a query
- MailboxPlan – Get all mailboxes that are assigned a specific mailbox plan
- RecipientTypeDetails – Return only the specified mailbox type
If you know the email address or name of the mailbox that you need, then the identity parameter is the most common way to select the mailbox:
# Find the mailbox on name or alias Get-Mailbox -Identity adelev # Using the email address to find the mailbox Get-Mailbox -Identity [email protected]
A faster option to find the mailbox that you need is to use the less known -anr
parameter. This will do a ambiguous name resolution search with the specified string and return all mailbox that matches. It searches on the following attributes:
- CommonName
- Displayname
- First and last name
- Alias
Important to note is that you will need to enter at least 3 characters of the mailbox name. So if we want to view the mailbox details from Adele Vance we can simply use the following command:
Get-Mailbox -anr ade
Using the Filter option
The Get-Mailbox cmdlet contains a lot of properties, and we can use most of them to filter the mailbox results. So let’s take a look at a couple of commonly used examples to find the mailboxes:
To find a mailbox on part of the name you could use the -anr
parameter, as mentioned before. But we can also use the filter of course. The advantage of filter over anr
is that you can filter all mailboxes that begin or end with the specified string:
# Get all mailboxes that start with 'di' Get-Mailbox -Filter "Displayname -like 'di*'" # Or get all mailboxes where the name ends with 'test' Get-Mailbox -Filter "Name -like '*test'"
Filter mailboxes on Quota’s
When you want to filter the mailboxes on one of the quotas (Archive, ProhibitSendQuota, IssueWarning, etc), then you may have noticed that you won’t be able to filter on the quota size. For example, this won’t work:
Get-Mailbox -Filter "IssueWarningQuota -lt '50GB'"
The problem is that you can only use the filter in combination with the quota to check if the property is set to unlimited or not:
# Get all mailboxes were the ProhibitSendReceiveQuota is set to unlimited Get-Mailbox -Filter "ProhibitSendReceiveQuota -eq 'Unlimited'" # Or not set to unlimited Get-Mailbox -Filter "ProhibitSendReceiveQuota -ne 'Unlimited'"
To “filter” on the actual value, we will need to get all mailboxes and use a where filter:
# Get all mailboxes where the issue warning quota is less then 50GB Get-Mailbox | where {$_.IssueWarningQuota -lt '50GB'}
Get Mailboxes based on the MailboxPlan
The -MailboxPlan parameter allows us to get all mailboxes that are assigned a specific mailbox plan. The first step is to get all available plans in your tenant:
Get-MailboxPlan | Select DisplayName | ft # Result DisplayName ----------- ExchangeOnline ExchangeOnlineEnterprise ExchangeOnlineEssentials ExchangeOnlineDeskless
We can use the display names from the plans to filter the mailboxes:
# Get all the mailboxes with the Exchange ONline plan (most of the time shared or resource mailboxes) Get-Mailbox -MailboxPlan ExchangeOnline
Filter on RecipientTypeDetails
In Exchange, there are different types of mailboxes. Besides the normal usermailbox, we have also the following types:
- RoomMailbox
- SharedMailbox
- TeamMailbox
- GroupMailbox
- EquipmentMailbox
And these are not even all types, but they are the most common ones. With the parameter RecipientTypeDetails, we can filter the results based on the mailbox type. So if you want to get all shared mailboxes, you can simply use the following cmdlet:
# Get all Shared mailboxes Get-Mailbox -RecipientTypeDetails SharedMailbox # Or all (meeting) room mailboxes Get-Mailbox -RecipientTypeDetails RoomMailbox
Retrieve all Mailboxes
To simply retrieve all mailboxes we don’t have to specify any filters. You only need to set the ResultSize
to unlimited:
Get-Mailbox -ResultSize unlimited
Tip
As mentioned in the beginning, it’s better to use the Get-EXOMailbox cmdlet with Exchange Online. It’s a lot faster then the Get-Mailbox cmdlet. For example, retrieving 230 mailboxes with Get-Mailbox takes 4.1 seconds and with Get-EXOMailbox only 2.4 seconds.
Get Inactive or Archive Mailboxes
To get all inactive mailboxes we can use the parameter -InactiveMailboxOnly
Get-Mailbox -InactiveMailboxOnly
And for archive mailboxes, you can use the parameter -Archive
Get-Mailbox -Archive
Get-Mailbox Properties
The Get-Mailbox cmdlet returns a lot of properties, almost 250! A lot of those properties are not relevant in most use cases. We can filter the results by selecting only the properties that we need, to get you started I have a couple of tips/examples for you.
Get-Mailbox -anr adel | Select DisplayName, PrimarySMTPAddress, RecipientTypeDetails, ProhibitSendReceiveQuota, WhenMailboxCreated, UsageLocation
To get all quotas from a mailbox we can use wildcards in the select statement:
Get-Mailbox -Resultsize unlimited | Select displayname, *quota* # Result ProhibitSendQuota : 99 GB (106,300,440,576 bytes) ProhibitSendReceiveQuota : 100 GB (107,374,182,400 bytes) RecoverableItemsQuota : 30 GB (32,212,254,720 bytes) RecoverableItemsWarningQuota : 20 GB (21,474,836,480 bytes) CalendarLoggingQuota : 6 GB (6,442,450,944 bytes) UseDatabaseQuotaDefaults : False IssueWarningQuota : 98 GB (105,226,698,752 bytes) RulesQuota : 256 KB (262,144 bytes) ArchiveQuota : 100 GB (107,374,182,400 bytes) ArchiveWarningQuota : 90 GB (96,636,764,160 bytes)
Export Mailbox information to CSV
The Get-Mailbox cmdlet is often used to extract mailbox information from the Exchange server. A good way to process the information further is to export the results to Excel. We can do this with the Export-CSV option. You can simply export any result set by piping Export-CSV behind your command:
# Export all mailbox quotas to CSV Get-Mailbox -Resultsize unlimited | Select displayname, *quota* | Export-CSV -NoTypeInformation
I have also created a couple of scripts related to mailbox information that you might find interesting:
Wrapping Up
Make sure that you also check out the new Exchange Online cmdlets, like Get-EXOMailbox, which offer better performance and are more reliable than the older cmdlets. For quickly looking up mailboxes make sure that your try the anr
parameter.
I hope you found this article useful, if you have any questions, just drop a comment below. You may also like the following articles: