What is a Get-Mailbox Cmdlet?
The Get-Mailbox cmdlet is a key command in the Exchange Management Shell (for Exchange Server) and in the Exchange Online PowerShell module (for Office 365). It is used to retrieve information about mailboxes in an Exchange environment. Whether you are dealing with user mailboxes, linked mailboxes, shared mailboxes, or resource mailboxes, with Get-Mailbox administrators can list all mailboxes within a specified scope, such as a database, server, or organizational unit, or retrieve detailed properties for a single mailbox. You can also filter results to return only the mailboxes that meet specific criteria.
The PowerShell Get-Mailbox cmdlet supports many parameters which can be used to customize the information returned. Parameters like -Properties allow for a comprehensive detail of mailbox attributes. The output of Get-Mailbox can be easily exported to CSV or JSON formats, facilitating integration with other tools and platforms. The Get-Mailbox cmdlet also provides the flexibility of PowerShell scripting in Exchange environments.
Availability in both on-premises Exchange and cloud-based service
The Get-Mailbox PowerShell cmdlet is available in both on-premises Exchange Server environments and Exchange Online (Office 365), though there are differences in implementation and available features. Introduced as part of Exchange Management Shell in Exchange Server 2007.
On-Premises Exchange Server
Get-Mailbox is available in Exchange Server 2010, 2013, 2016, and 2019. Get-Mailbox is used via the Exchange Management Shell (EMS) in on-premises Exchange or via PowerShell loading the Exchange module. It includes parameters for filtering by database, organizational unit, recipient type, and more. Outputs various mailbox properties such as name, email address, and mailbox database.
Exchange Online (Office 365)
Get-Mailbox via PowerShell can be used for Exchange Online, which is accessed via remote PowerShell connections. This module provides cloud-based management capabilities and is accessed remotely. Like on-premises Exchange but may include additional parameters or features optimized for the cloud environment. Output includes properties relevant to cloud management.
Recommendation for using Get-EXOMailbox cmdlet in Exchange Online
The Get-EXOMailbox cmdlet is part of the Exchange Online PowerShell module and is used to retrieve information about mailboxes in Exchange Online (part of Office 365). This cmdlet is an alternative to Get-Mailbox with enhancements for Exchange Online. Get-EXOMailbox is optimized for cloud environments and may provide better performance and additional features designed for Office 365. This cmdlet offers more advanced filtering and querying options that are specifically useful in a cloud-based setup and is better integration with other Office 365 services and features.
Recommendations for Using Get-EXOMailbox
- When working in Exchange Online, use Get-EXOMailbox rather than Get-Mailbox for optimized performance and cloud-specific features.
- Use the -Filter parameter to efficiently retrieve subsets of mailboxes based on specific criteria, reducing the load and improving query performance.
- For large organizations, use -ResultSize Unlimited to ensure you capture all relevant mailboxes. Be mindful of performance implications with very large data sets.
- Use Get-EXOMailbox into PowerShell scripts for automated reporting, management, and maintenance tasks in Exchange Online.
Get-Mailbox Cmdlet’s Function
The Get-Mailbox cmdlet in Exchange Server and Exchange Online is used to retrieve detailed information about mailboxes. The cmdlet does not modify any data, its primary function is to gather and display mailbox properties and configurations, this includes data about mailbox sizes, quotas, the number of items, last accessed time, and much more. The cmdlet provides flexibility in targeting specific mailboxes, sets of mailboxes, or all mailboxes, depending on the parameters used.
Purpose
The Get-Mailbox cmdlet retrieves information about mailboxes, including user mailboxes, shared mailboxes, resource mailboxes (like room, shared and equipment mailboxes), and others. It provides details such as mailbox properties, location, and configuration.
Primary Uses
Generate lists of mailboxes for reporting purposes, such as auditing mailbox types, locations, and attributes. Retrieve details needed for mailbox management tasks, like configuring mailbox settings or performing bulk operations. Help diagnose issues by providing mailbox-specific information related to configurations, quotas, and more.
Operation
When you execute the Get-Mailbox cmdlet, it queries the Exchange directory services, Active Directory in on-premises environments, or Exchange Online directory in Office 365, to retrieve mailbox information. The cmdlet fetches data from the mailbox database or directories and presents it based on the specified parameters. This includes properties like email addresses, mailbox sizes, and more.
Output
By default, Get-Mailbox displays a set of common properties such as DisplayName, PrimarySmtpAddress, Database, and Recipient Type. The output can be customized using the Select-Object to display additional or specific properties.
Parameters
Parameters like -Identity, -Database, -OrganizationalUnit, and -Filter allow you to narrow down the search to specific mailboxes or sets of mailboxes based on criteria such as database location, organizational unit, or custom attributes. -ResultSize lets you control the number of results returned, which is helpful for managing performance and focusing on relevant subsets of data. Get-Mailbox supports many other parameters for more tasks.
Permissions required to run Get-Mailbox Cmdlet
Specific permissions are required to run the Get-Mailbox cmdlet in Exchange Server and Exchange Online. These permissions determine who can execute the cmdlet to retrieve mailbox information. These permissions are typically assigned through role-based access control (RBAC) in Exchange. These roles typically include “Recipient Management,” “Organization Management” or “View-Only Organization Management.” Below is a detailed overview of the permissions required for running the Get-Mailbox cmdlet.
Exchange Server (On-Premises)
In an on-premises Exchange Server environment, permissions typically granted through role-based access control (RBAC). RBAC roles can be assigned at several scopes, from organization-wide to specific mailbox databases.
Recipient Management Role
For general mailbox management, including running Get-Mailbox, users are typically added to the “Recipient Management” role group. This role group includes roles that allow for creating, managing, and removing mailboxes, among other recipient-related tasks.
Organization Management Role
For high level administrative privileges, including the ability to run all mailbox-related cmdlets, the “Organization Management” role group can be used, that grant permissions across the entire Exchange organization.
View-Only Organization Management Role
This role provides read-only access to organizational settings, including the ability to run Get-Mailbox but without the ability to modify settings.
Custom RBAC Roles
You can also create custom roles that specifically include the Get-Mailbox cmdlet, customizing the permissions to specific needs without granting broader access than necessary.
Exchange Online (Office 365)
In Exchange Online for Get-Mailbox, permissions are similarly managed through RBAC, part of the overall Office 365 permissions structure, all above mentioned roles for on-premises Exchange server are also available, but there are some more high-level roles mentioned below, which also have permissions to run Get-Mailbox cmdlet.
Global Administrator
Users with the Global Administrator role have the permissions to run Get-Mailbox alongside other administrative cmdlets across the entire Exchange Online organization.
Exchange Administrator Role
Specific to Exchange Online, the Exchange Administrator role provides necessary permissions to manage Exchange settings, objects management, including executing Get-Mailbox.
Customized Administrator Roles
Office 365 allows for the creation of customized administrator roles, like Exchange on-premises. A custom role can include the Get-Mailbox cmdlet specifically, along with any other required cmdlets, offering precise control over permissions.
Syntax for Get-Mailbox Cmdlet
Basic Syntax
The most straightforward use of the Get-Mailbox cmdlet is to get all mailboxes using PowerShell. The cmdlet returns a summary list of all mailboxes when used without any parameters, including primary attributes like DisplayName, Alias, ServerName, ProhibitSendQuota, and others depending on the environment.
Get-Mailbox
General syntax
The general structure of the Get-Mailbox with several parameters is as follows.
Get-Mailbox [-Identity <MailboxIdParameter>] [-Database <DatabaseIdParameter>] [-OrganizationalUnit <OrganizationalUnitIdParameter>] [-RecipientTypeDetails <RecipientTypeDetails>] [-Filter <FilterExpression>] [-ResultSize <Unlimited | Integer>] [-DomainController <Fqdn>] [-ReadFromDomainController] [-Anr <String>] [-IncludeSoftDeletedMailboxes] [-MessageTrackingLogPath <String>] [-ResultSize <Unlimited | Integer>]
Below is general syntax with one parameter
Get-Mailbox [-Parameter <value>]
Commonly used Get-Mailbox Parameters
The following are commonly used Get-Mailbox parameters:
Get-Mailbox Parameters | Syntax |
---|---|
-Identity Parameter | Get-Mailbox -Identity “BarbaraCole” |
-Filter Parameter | Get-Mailbox -Filter {Name -like “Bar*”} Get-Mailbox -Filter {DisplayName -like “Bar*”} Get-Mailbox -Filter {CustomAttribute1 -like ‘TeamA’} |
-Database Parameter | Get-Mailbox -Database “ Mailbox Database 1767124038″ |
-OrganizationalUnit Parameter | Get-Mailbox -OrganizationalUnit “OU=Versacorp,DC=MILKYWAY,DC=LOCAL” |
-Arbitration Parameter | Get-Mailbox -Arbitration |
-AuditLog Paramter | Get-Mailbox -AuditLog |
-RecipientTypeDetails Parameter | Get-Mailbox -RecipientTypeDetails SharedMailbox |
-ResultSize Parameter | Get-Mailbox -ResultSize 10 |
-SoftDeletedMailbox Parameter | Get-Mailbox -SoftDeletedMailbox |
-Anr | Get-Mailbox -Anr “Adita” |
-SortBy | Get-Mailbox -SortBy Name |
Let’s look at each of them
-Identity Parameter
The -Identity parameter specifies the mailbox to be retrieved. It can accept several forms of identifiers such as the mailbox GUID, Distinguished Name (DN), Domain\Username, User Principal Name (UPN), Legacy Exchange DN, SMTP address, or Alias. This parameter can be used to quickly access information about a specific mailbox.
Get-Mailbox -Identity "BarbaraCole"
-Filter Parameter
The -Filter parameter allows for more complex queries. It is used to define conditions that pinpoint the exact set of mailboxes you are interested in, based on attributes such as department, custom attributes, or mailbox size.
Get-Mailbox -Filter {Name -like "Bar*"}
Get-Mailbox -Filter {DisplayName -like "Bar*"}
Get-Mailbox -Filter {CustomAttribute1 -like 'TeamA'}
-Database Parameter
The -Database parameter filters mailboxes based on the database in which they are stored. It is useful for operations targeting specific databases, such as during migrations or for database-specific reporting.
Get-Mailbox -Database " Mailbox Database 1767124038"
-OrganizationalUnit Parameter
The -OrganizationalUnit parameter narrows down the search to mailboxes located within a specific Active Directory organizational unit. This is particularly handy in large organizations with a structured OU hierarchy.
Get-Mailbox -OrganizationalUnit "OU=Versacorp,DC=MILKYWAY,DC=LOCAL"
-Arbitration Parameter
The -Arbitration switch parameter retrieves arbitration mailboxes, which are system mailboxes used for storing organizational data, such as administrator audit logs, eDiscovery information, and other system-related tasks.
Get-Mailbox -Arbitration
-AuditLog Parameter
The -AuditLog switch parameter is used to retrieve audit log mailboxes, which contain audit logs for actions taken by administrators and users. This is important for compliance and monitoring purposes.
Get-Mailbox -AuditLog
-RecipientTypeDetails Parameter
This parameter allows filtering of the mailboxes based on their type, such as UserMailbox, SharedMailbox, RoomMailbox, or EquipmentMailbox, among others. It facilitates operations aimed specifically at managing particular types of mailboxes.
Get-Mailbox -RecipientTypeDetails SharedMailbox
-ResultSize Parameter
The -ResultSize parameter limits the number of results returned by the cmdlet. By default, Get-Mailbox retrieves up to 1000 mailboxes. Setting this parameter to “Unlimited” allows fetching details for all mailboxes without truncation or setting it to a less number e.g. 50 will bring results according to value provided.
Get-Mailbox -ResultSize 10
-SoftDeletedMailbox Parameter
Retrieve mailboxes that have been soft deleted but not permanently removed, this parameter is only available for Exchange Online (Office365).
Get-Mailbox -SoftDeletedMailbox
-Anr
The -Anr (Ambiguous Name Resolution) parameter is used in conjunction with the -Identity parameter to search for a mailbox where the specified string is close or similar to the actual identity of the mailbox. It is helpful when the exact name or alias of the mailbox is not known.
Get-Mailbox -Anr "Adita"
-SortBy
This parameter specifies the property by which the results should be sorted. For instance, using -SortBy DisplayName, organizes the returned mailbox list alphabetically by the display name of the mailboxes.
Get-Mailbox -SortBy Name
Common Parameters
Like other cmdlets in PowerShell Get-Mailbox supports common parameters like -Verbose, -Debug, -ErrorAction, -ErrorVariable, -WarningAction, -WarningVariable, -OutBuffer, -PipelineVariable, and -OutVariable. These parameters can help control cmdlet messaging, handle errors and warnings, and manage output in scripts and functions.
Other Parameters available for cmdlet
-Archive: Returns mailboxes with archives enabled
-AuxAuditLog: Returns auxiliary audit log mailboxes
-Credential: Specifies username and password
-DomainController: Specifies the domain controller
-GroupMailbox: Returns only Microsoft 365 Groups
-IgnoreDefaultScope: Ignores default recipient scope
-InactiveMailboxOnly: Returns only inactive mailboxes
-IncludeInactiveMailbox: Includes inactive mailboxes
-MailboxPlan: Filters results by mailbox plan
-Migration: Returns migration mailboxes
-Monitoring: Returns monitoring mailboxes
-PublicFolder: Returns public folder mailboxes
-ReadFromDomainController: Reads information from domain controller
-RemoteArchive: Returns remote archive mailboxes
-Server: Filters results by Exchange server
Combining Parameters
You can combine multiple parameters to refine your query. Following are some examples.
- Below cmdlet retrieves all user mailboxes in a specific database with recipient type as “user”.
Get-Mailbox -Database "Test3" -RecipientTypeDetails UserMailbox
- Below cmdlet will get all the mailboxes with a specific custom attribute, with all the results using -ResultSize.
Get-Mailbox -Filter {CustomAttribute1 -eq “TeamA”} -ResultSize Unlimited
By piping the Get-Mailbox cmdlet output into the Select-Object cmdlet, below example cmdlets retrieves customized list showing the display name, primary SMTP address, and send quota for each mailbox from a specific OU. This format is particularly useful for generating reports or audits.
- Retrieve mailboxes in a specific OU and show only their display names and email addresses.
Get-Mailbox -OrganizationalUnit "OU=Versacorp,DC=MILKYWAY,DC=LOCAL" | Select-Object DisplayName,PrimarySmtpAddress
- Listing All Mailboxes with Detailed Properties
Get-Mailbox | Select-Object DisplayName, PrimarySmtpAddress, ProhibitSendQuota
- More complex example shown below, combines multiple cmdlets to identify mailboxes that have not been accessed in the last 90 days.
Get-Mailbox -ResultSize Unlimited | Get-MailboxStatistics | Where-Object {$_.LastLogonTime -lt (Get-Date).AddDays(-90)}
Use cases and scenarios
Get-Mailbox combined with its parameters, enables a wide range of uses and scenarios that can facilitate effective email system management, compliance, reporting, and troubleshooting. Below are some use cases and scenarios.
Mailbox Auditing and Reporting
Generating reports on mailbox sizes, quotas, and usage to ensure compliance with organizational policies. Below cmdlet does not produce any results, you can go to the location provided in Export-CSV cmdlet and open the CSV file, it will look like below screenshot.
Get-Mailbox -ResultSize Unlimited | Get-MailboxStatistics | Select DisplayName, TotalItemSize, ItemCount, StorageLimitStatus | Export-Csv -Path "MailboxReport.csv"
Identifying Inactive or Orphaned Mailboxes
Finding mailboxes that have not been accessed for a specific period, which might indicate inactive or orphaned mailboxes. This scenario helps in cleaning up the mail system, potentially freeing up resources and licenses by identifying mailboxes that are no longer in use.
Get-Mailbox -ResultSize Unlimited | Get-MailboxStatistics | Where-Object {$_.LastLogonTime -lt (Get-Date).AddMonths(-6)} | Select DisplayName, LastLogonTime
Managing Mailbox Configurations
Listing mailboxes with certain configurations, such as forwarding enabled or specific mailbox features.
Get-Mailbox -ResultSize Unlimited | Where {$_.ForwardingAddress -ne $null} | Select DisplayName, ForwardingAddress
Bulk Management
Perform bulk operations, such as moving mailboxes or applying mailbox settings to multiple mailboxes at once. Move all mailboxes from one database to another as part of a maintenance task.
Get-Mailbox -Database "DB01" | New-MoveRequest -TargetDatabase "DB05"
Bulk Operations and Delegations
Finding all shared or delegate mailboxes and reviewing their delegated users for audit purposes.
Get-Mailbox -RecipientTypeDetails SharedMailbox -Database “Test3” | Get-MailboxPermission | Where {$_.AccessRights -contains "FullAccess"}
Setting quotas for mailbox
If you want to set send and receive quota according to your need, below cmdlet will be able set the quota with value of 5GB, you can use your own value as required.
Get-Mailbox -Identity "JackRobert" | Set-Mailbox -ProhibitSendReceiveQuota "5GB"
Above cmdlet will not produce any output but will set the value, you can use the below cmdlet to check the desired output you set using above cmdlet.
Get-Mailbox -Identity "JackRobert" | Select prohibitsendreceivequota
Troubleshooting
Diagnose and troubleshoot issues related to mailboxes, such as identifying mailboxes with exceeded quotas. Identify mailboxes that have exceeded their send quotas to address potential performance issues.
Get-Mailbox -ResultSize Unlimited | Where-Object { $_.ProhibitSendQuota -ne $null -and $_.ProhibitSendQuota -lt 5GB } | Select-Object DisplayName,PrimarySmtpAddress,ProhibitSendQuota
Organizational Unit Management
Manage mailboxes within a specific organizational unit (OU), such as applying specific settings or configurations. Retrieve and apply a configuration change to all mailboxes in the “HR” OU.
Get-Mailbox -OrganizationalUnit "OU=Test,DC=MILKYWAY,DC=LOCAL " | Set-Mailbox -MaxSendSize 50MB
Above cmdlet will not produce any results but will assign the value for maximum send size for messages, for all users within the OU specified, use the below cmdlet to confirm.
Get-Mailbox -OrganizationalUnit "OU=Test,DC=MILKYWAY,DC=LOCAL " | Select MaxSendSize
Delegate Access
Delegate access to mailboxes for administrative or support purposes. Grant full access permissions to a support mailbox for all mailboxes in a specific mailbox database.
Get-Mailbox -Database “Test3” | Add-MailboxPermission -User "administrator@milkyway.local" -AccessRights FullAccess
Checking mailbox quota settings
Checking mailbox quota settings is important, as it helps ensure that users do not exceed the storage limits set by the organization, potentially impacting email functionality.
Mailbox Quota Overview
Mailbox quotas are used to limit the amount of storage space a mailbox can use. These quotas include as below.
- Issue Warning Quota: The threshold at which users are warned that their mailbox is approaching its storage limit.
- Prohibit Send Quota: The threshold at which users are prevented from sending new messages.
- Prohibit Send and Receive Quota: The threshold at which users are prevented from sending or receiving new messages.
To check the quota settings for a specific mailbox, you can use the Get-Mailbox cmdlet followed by the mailbox identity. This will return various properties of the mailbox, including the quota settings.
Get-Mailbox -Identity "BarbaraCole" | Format-List IssueWarningQuota, ProhibitSendQuota, ProhibitSendReceiveQuota, UsedDatabaseQuotaDefaults
If you need to review the quota settings across multiple or all mailboxes within your environment, you can use the Get-Mailbox cmdlet without specifying an identity and output the relevant quota properties, and exports the data to a CSV file, making it easier to analyze and report on quota configurations.
Get-Mailbox -ResultSize Unlimited -Database “Test3” | Select-Object DisplayName,ProhibitSendQuota,ProhibitSendReceiveQuota,IssueWarningQuota
Example1: Returning a summary list of all mailboxes
To return a summary list of all mailboxes in Exchange Online or Exchange Server using PowerShell, use the below cmdlet.
Below command will output a table to your PowerShell console containing a summary of all mailboxes with their display names, aliases, UPNs, creation dates, and primary email addresses. This summary provides a quick overview, useful for reports, audits, or simply getting an insight into the mailboxes currently established in your Exchange environment.
Get-Mailbox -ResultSize Unlimited | Select-Object DisplayName, Alias, UserPrincipalName, WhenCreated, PrimarySmtpAddress | Format-Table -AutoSize
Below cmdlet will use some more properties e.g. Database, ProhibitSendQuota, ProhibitSendReceiveQuota, IssueWarningQuota, along with display name and primary smtp address.
Get-Mailbox -ResultSize Unlimited | Select-Object DisplayName,PrimarySmtpAddress,Database,ProhibitSendQuota,ProhibitSendReceiveQuota,IssueWarningQuota | Format-Table -Autosize
Example2: Returning a summary list of archive mailboxes in a specific database
To return a summary list of archive mailboxes located within a specific database using PowerShell in Exchange Online or Exchange Server, you can use a combination of the “Get-Mailbox and” and “Get-MailboxStatistics” cmdlets. This combination allows you to filter mailboxes by their hosting database and then check each for an archive. Below is how you can accomplish this.
Get-Mailbox -Database "Test3" -Archive | Get-MailboxStatistics -Archive | Select-Object DisplayName, TotalItemSize, ItemCount | Format-Table -AutoSize
Combining Get-Mailbox with other cmdlets (Get-Member, Select-Object, Format-List)
Combining the Get-Mailbox cmdlet with other PowerShell cmdlets like Get-Member, Select-Object, and Format-List can help you retrieve, view, and format mailbox information more effectively.
Get-Member
The Get-Member cmdlet is used to inspect the properties and methods of objects returned by Get-Mailbox. This is particularly useful for discovering which properties are available for selection or formatting.
Get-Mailbox -Identity "BarbaraCole@milkyway.local" | Get-Member
Select-Object
The Select-Object cmdlet allows you to specify which properties you want to include in your output. This is useful for creating a tailored view of mailbox information.
Get-Mailbox -ResultSize Unlimited | Select-Object DisplayName, PrimarySmtpAddress,Database
Format-List
The Format-List cmdlet formats output as a list, showing all properties and their values. This is useful for a detailed view of a mailbox object’s properties.
Get-Mailbox -Identity "BarbaraCole@milkyway.local" | Format-List DisplayName, PrimarySmtpAddress, ProhibitSendQuota
Bulk Operations with Get-Mailbox and Set-Mailbox
You want to update mailbox settings for multiple mailboxes, such as setting a specific mailbox quota or enabling/disabling archiving.
Below command finds all mailboxes in “Test3” and sets their quota settings. It updates the ProhibitSendQuota, ProhibitSendReceiveQuota, and IssueWarningQuota for each mailbox.
Get-Mailbox -ResultSize Unlimited | Where-Object { $_.Database -eq "Test3" } | Set-Mailbox -ProhibitSendQuota 5GB -ProhibitSendReceiveQuota 6GB -IssueWarningQuota 4GB
Using filters and sorting results
When working with large sets of information, you can narrow down the dataset to exactly what you need, and sorting helps organize the output for better analysis or reporting. Below cmdlets will show how to use filtering and sorting mechanisms with Get-Mailbox.
Using Filters in Get-Mailbox
Filtering cmdlets allow you to specify criteria to include only the objects that match those criteria in the command’s output, you can apply filters directly in cmdlets that support the -Filter parameter or use the “Where-Object” cmdlet for more complex or unsupported filtering scenarios.
Get-Mailbox -ResultSize Unlimited | Where-Object {$_.CustomAttribute1 -eq "TeamA" -and $_.DisplayName -like "Barb*"}
Sorting Results with Get-Mailbox
Sorting helps in organizing your data in a meaningful order, making it easier to read and analyze. You can use the “Sort-Object” cmdlet for sorting purposes. This command retrieves all mailboxes and sorts them alphabetically by their display name.
Get-Mailbox -ResultSize 10 | Sort-Object DisplayName
Exporting results to CSV
To export results to a CSV file, PowerShell offers the “Export-Csv” cmdlet, which takes input from the pipeline and writes it to a specified CSV file. For example, if you want to export a list of Exchange mailboxes along with their sizes and usage details, you can use the below cmdlet. You need to specify the path and filename for your CSV file in -Path parameter.
Get-Mailbox -ResultSize Unlimited | Get-MailboxStatistics | Select-Object DisplayName, TotalItemSize, ItemCount | Export-Csv -Path "C:\Exports\MailboxDetails.csv" -NoTypeInformation
Grouping and formatting results
Grouping and formatting results significantly enhance the readability of your data output. PowerShell provides cmdlets such as Group-Object, Format-Table, Format-List, etc., which can be used for these purposes.
Grouping Results
The Group-Object cmdlet is for categorizing objects based on property values. This can be particularly useful for sorting mailboxes by attributes, like department or custom attributes.
Get-Mailbox -ResultSize Unlimited | Group-Object -Property CustomAttribute1
Formatting Results
After the data is grouped or when presenting any data, proper formatting can make the output more accessible. Format-Table, often abbreviated as “ft”, displays data in a table format. It is ideal for when you want to see your results in columns. You can specify the properties to display and even control the column width.
Get-Mailbox -Identity "BarbaraCole@milkyway.local" | Format-Table DisplayName,UserPrincipalName,WhenCreated,PrimarySmtpAddress,database -AutoSize
Using “Format-List”
Format-List, abbreviated as “fl”, displays each property of an object on a new line, making it suitable for detailed viewing of fewer objects or when the object has many properties that would not fit well in a table.
Get-Mailbox -Identity "BarbaraCole" | Format-List DisplayName, PrimarySmtpAddress, EmailAddresses
Differences in cmdlet behavior in Exchange Online
Get-Mailbox cmdlet behaves slightly differently in Exchange online compared to its usage in on-premises Exchange. These differences are primarily from the cloud-based architecture of Exchange Online and the multi-tenant setup, which impacts how administrators interact with mailboxes and the scope of the cmdlets. Below are some key differences.
- In Exchange Online, cmdlet operations can be subject to throttling to maintain overall service performance, might take longer or require batch processing in larger environments to avoid throttling limits.
- Exchange Online includes more recipient types and details to accommodate the variety of services in Office 365, you might encounter recipient types that are specific to the cloud environment that do not exist in on-premises Exchange.
- Some properties and attributes available in on-premises Exchange might not be present or accessible in Exchange Online due to the nature of the hosted environment. Exchange Online mailboxes might have additional properties related to the cloud environment, like licensing information and mailbox plans.
- The default output in Exchange Online is different for cloud management, providing information more relevant to cloud administrators. The set of properties displayed by default and the built-in filters might differ from those in an on-premises Exchange.
- Due to the multi-tenant architecture of Exchange Online, the scope of Get-Mailbox is limited to the organization’s mailboxes. In a hybrid environment, to manage on-premises mailboxes, administrators need to use the on-premises Exchange Management Shell.
- Exchange Online integrates closely with other Office 365 services, offering advanced security and compliance features. The behavior of Get-Mailbox might reflect these integrations, such as flags or properties related to litigation hold, eDiscovery, or Advanced Threat Protection.
Using Get-EXOMailbox for better performance
Get-EXOMailbox is a cmdlet designed for use in Exchange Online environments. It offers improved performance and specific functionalities to the cloud-based nature of Exchange Online compared to the traditional Get-Mailbox cmdlet. Get-EXOMailbox is optimized for faster execution over remote connections, making it more efficient for retrieving mailbox information from Exchange Online. Connection requires modern authentication, potentially including multi-factor authentication (MFA), depending on your environment’s configuration.
Connect-ExchangeOnline -UserPrincipalName administrator@milkyway.com
Below are a couple of examples showing how “Get-EXOMailbox” can be used for common administrative tasks.
Get-EXOMailbox -ResultSize Unlimited
Filter by Recipient Type
Get-EXOMailbox -RecipientTypeDetails SharedMailbox | Format-Table -Autosize
Filter by Archive Status
Get-EXOMailbox -Filter { ArchiveStatus -eq "Active" } Format-Table -Autosize
Archiving in Office 365 is a premium feature, I have used the ArchiveStatus to None to show the output as below, the above cmdlet will work if there will be mailboxes with archiving enabled.
Select Specific Properties
Get-EXOMailbox -ResultSize Unlimited | Select-Object DisplayName,PrimarySmtpAddress,UserPrincipalName
Sort by Display Name
Get-EXOMailbox -ResultSize Unlimited | Select-Object DisplayName,UserPrincipalName | Sort-Object DisplayName
Get-Mailbox Exclusive parameters for Exchange Online
Get-Mailbox cmdlet includes parameters that are exclusive to Exchange Online or have relevance in a cloud-hosted environment compared to an on-premises Exchange Server setup. These exclusive parameters provide unique characteristics of managing mailboxes in the cloud, such as dealing with licensing, listing inactive mailboxes or retrieving soft deleted mailboxes.
-InactiveMailboxOnly
You can choose whether to limit the results to only inactive mailboxes by using the -InactiveMailboxOnly parameter. This switch does not require a value to be specified.
A mailbox that is put on litigation hold or in-place hold prior to being soft-deleted is considered inactive.
-MailboxPlan
This parameter is filtering the mailboxes returned by the command to only those that are associated with a specific mailbox plan. This feature is especially useful in environments where multiple mailbox plans are in place, such as different plans for different departments or roles within an organization.
-IncludeInactiveMailbox
This parameter includes inactive mailboxes in the results. Inactive mailboxes are usually related to deleted or deprovisioned users but are retained for data retention purposes, especially important for compliance and eDiscovery.
-SoftDeletedMailbox
This parameter includes mailboxes in the results that have been soft deleted. Soft deleted mailboxes occur when a mailbox is deleted through the Office 365 admin center or via PowerShell, but it is retained for a period to allow for recovery.
Get-Mailbox best practices
When it comes to managing mailboxes in a Microsoft Exchange environment using Get-Mailbox cmdlet, adhering to best practices ensure optimal performance, security, and manageability. Below are some key best practices to consider.
Limit the Scope of Your Queries
Use filters to narrow down the results to only the mailboxes you are interested in. This reduces the load on your system and gets you the information more quickly. When running “Get-Mailbox”, especially in large environments, try to limit the scope of the command to the necessary mailboxes. Use parameters like “-RecipientTypeDetails” or “-OrganizationalUnit” to narrow down the results and reduce load on your Exchange server.
Use Server-Side Filtering
Whenever possible, use cmdlet parameters that perform filtering on the server side instead of bringing all objects into memory and filtering client-side with “Where-Object”. This improves performance and efficiency. Leverage the “-Filter” parameter to perform server-side filtering. This approach is more efficient and reduces the amount of data transmitted over the network.
Use Result Size Limitations Wisely
Be cautious with the “-ResultSize Unlimited” parameter, especially in large environments. While it is necessary for comprehensive operations, it can lead to performance issues. Consider breaking down large operations into smaller chunks.
Selective Property Retrieval
By default, Get-Mailbox retrieves a lot of properties for each mailbox, which may not always be necessary. Use the “-Properties” parameter to specify only the properties you need, or use “Select-Object” to trim down the results. This can significantly improve performance.
Efficient Use of Wildcards
When using wildcards (*) in filters, be aware that they can lead to performance issues if used excessively or inefficiently. Place wildcards carefully within your queries to ensure they are as efficient as possible.
Combine with Other Cmdlets Wisely
Often, “Get-Mailbox” is used in conjunction with other cmdlets for tasks such as mailbox modifications or reports. When piping “Get-Mailbox” into other cmdlets, ensure that the initial “Get-Mailbox” command is as targeted as possible to avoid unnecessary processing.
Understand the Impact of RecipientTypeDetails
This parameter is incredibly useful for targeting specific types of mailboxes (e.g., UserMailbox, SharedMailbox, etc.). Understanding and using this parameter effectively can help in executing more precise operations.
Security and Compliance
When running “Get-Mailbox” scripts or commands that might expose sensitive information, ensure that you are in compliance with your organization’s security policies. Limit access to these scripts and their output to authorized personnel only.
Test and Validate Scripts
Before running a script that makes changes based on “Get-Mailbox” output, especially in a production environment, thoroughly test your script in a non-production environment. Validate the selection of mailboxes and the intended changes to avoid unintended impacts.
Regularly Review and Update Scripts
As your Exchange environment evolves, so too should your scripts and commands. Regularly review and update them to ensure they are using the most efficient methods and are aligned with current best practices.
Stay Current
Ensure your PowerShell session or module for Exchange is up to date. Microsoft regularly updates PowerShell cmdlets for Exchange Online, introducing new features and improvements that can enhance your scripting capabilities.
Get-Mailbox Troubleshooting common issues
You might encounter several issues or unexpected behaviors when working with Get-Mailbox cmdlet. Below are some common issues along with troubleshooting steps and solutions to resolve them effectively.
Cmdlet Not Recognized
You may receive an error message indicating that “Get-Mailbox” is not recognized as the name of a cmdlet, function, script file, or operable program.
Troubleshooting Steps
- Ensure you are running the cmdlet in the Exchange Management Shell (for Exchange Server) or have connected to Exchange Online PowerShell using “Connect-ExchangeOnline” (for Exchange Online).
- For Exchange Online, ensure the Exchange Online PowerShell Module is installed and up to date.
- Check your PowerShell session, you might be in a session that does not load the Exchange cmdlets by default.
Insufficient Permissions
You are connected to Exchange Online or Exchange Server but receiving permission-related errors when attempting to execute “Get-Mailbox”.
Troubleshooting Steps
- Verify the account you are using has the necessary permissions (e.g., Exchange Admin role for Exchange Online or appropriate RBAC roles in Exchange Server).
- For Exchange Online, ensure that you have multi-factor authentication (MFA) set up correctly if your account requires it.
- In Exchange Server, check that the account is explicitly granted access to use “Get-Mailbox” or added in a role that permit the operation, e.g. Recipient Management role.
Incomplete or Unexpected Results
The “Get-Mailbox” cmdlet executes without errors but returns incomplete or unexpected results.
Troubleshooting Steps
- Use the “-ResultSize” parameter to ensure all expected mailboxes are being queried. The default might not return all mailboxes.
- Refine your query using the “-Filter” parameter to ensure it accurately reflects the criteria you want to apply.
- Check if there are any server-side or client-side filtering options that might be limiting the results.
- For Exchange Online, throttling policies can sometimes delay command execution, consider retrying after a brief interval.
Performance Issues
The cmdlet takes a long time to execute, especially in environments with a large number of mailboxes.
Troubleshooting Steps
- Limit your query scope using “-ResultSize”, “-Filter”, or other specific parameters like “-OrganizationalUnit” to narrow down the results and improve performance.
- Consider breaking down your task into smaller batches if you are processing a large number of mailboxes.
- For Exchange Online, ensure you are using the latest version of the Exchange Online Management Module which is optimized for large datasets.
Connectivity Issues
You experience connectivity issues when trying to use “Get-Mailbox” in Exchange Online.
Troubleshooting Steps
- Ensure your internet connection is stable.
- Confirm that there are no ongoing service incidents affecting Exchange Online by checking the Office 365 Service Health dashboard.
- Re-establish your PowerShell session to Exchange Online using “Connect-ExchangeOnline”, as session timeouts or network changes can disrupt connectivity.
Script Execution Policy Restrictions
You encounter restrictions related to PowerShell script execution policy when running scripts that include the “Get-Mailbox” cmdlet.
Troubleshooting Steps
- Use “Get-ExecutionPolicy” to check your current PowerShell execution policy.
- If necessary, adjust the policy using “Set-ExecutionPolicy” with an appropriate level (e.g., RemoteSigned) that allows your script to run, considering the security implications.
FAQs
What does get-mailbox do?
Get-Mailbox retrieve the mailbox information from an on-premises Exchange or Exchange Online (Office 365).
What is the difference between get-mailbox and get-EXOMailbox?
The difference between Get-Mailbox and Get-EXOMailbox primarily relates to the environments they are used in and the type of mailboxes they target. Get-Mailbox is used in on-premises Exchange environments but can also be used with Exchange online. Get-EXOMailbox is specifically used in Exchange Online. It is part of the Exchange Online PowerShell module, which is specifically designed for managing Exchange Online.
What is the get-mailbox statistics command?
The Get-MailboxStatistics command in PowerShell is used to retrieve statistical information about mailboxes in an Exchange environment. This command provides details such as, total item count, total size of the mailbox, last logon time etc. This command is useful for administrators to monitor mailbox usage and performance.
How to get-mailbox details in PowerShell?
To get mailbox details in PowerShell, you can use the Get-Mailbox command. This command allows you to retrieve several properties of mailboxes in both on-premises Exchange and Exchange Online environments.
What is the command to get-mailbox database in PowerShell?
To get mailbox database details in PowerShell, you can use the Get-MailboxDatabase command in an on-premises Exchange environment. For Exchange Online, this command is not applicable since it operates differently.
How to get-mailbox folder list in PowerShell?
To get a list of mailbox folders in PowerShell, you can use the Get-MailboxFolderStatistics command. This command provides details about the folders within a specific mailbox, including their names, sizes, and item counts.
How do I get the properties of a mailbox in PowerShell?
You can use the Get-Mailbox to show all properties of a mailbox in an on-premises Exchange or the Exchange Online.
Get-Mailbox -Identity “BarbaraCole@milkyway.local” | Format-List
This will display all available properties for the specified mailbox.