‘Deep Dive’ into Office 365 PowerShell cmdlets: Mailbox information

As powerful as Office 365 is, it can be made even more powerful with simple PowerShell cmdlets that can streamline your work and make your life easier. In today’s “Deep Dive,” we look at how to use PowerShell to collect mailbox information from Exchange Online.

In the previous article in this series, we explained how you can use a few simple steps to connect to Office 365 Exchange Online Service using PowerShell. This part helps you understand necessary Exchange Online PowerShell cmdlets that you may find useful and Exchange Online PowerShell cmdlets that help you reduce the time it takes to perform tasks that you usually do using the Office 365 Admin Center. We will also explain how you can use the Get-MailBox cmdlet to collect mailboxes information from Exchange Online. In the next and subsequent parts, we will continue to provide some more examples of the Get-MailBox cmdlet.

Overview of Office 365 Exchange Online cmdlets

You might have worked with the Get-MailBox PowerShell cmdlet that helps you collect mailbox information from Exchange Online, but you might not be aware of all the cmdlets that Microsoft provides to manage Exchange Online. Microsoft provides PowerShell cmdlets to manage different aspects of Exchange Online Service. For example, to manage client access in Exchange Online, you will use Client Access cmdlets such as Get-OwaMailBoxPolicy, New-OwnMailBoxPolicy, Set-MailBoxSpellingConfiguration, Get-MailBoxMessageConfiguration, and so on. Similarly, to manage organizations in Exchange Online cmdlet, you will use organization PowerShell cmdlets such as Get-MailBoxPlan, Set-MailBoxPlan, Get-OrganizationConfig, Enable-OrganizationCustomization, and so on. There are other Exchange Online PowerShell cmdlets, but in this part, we will focus on PowerShell cmdlets that you may find useful to interact with mailboxes hosted at Exchange Online.

Collecting mailbox information from Exchange Online

Connect to Exchange Online. (The necessary steps to do this were provided in the previous article in this series.) Please make sure to follow all the steps outlined to connect to Exchange Online before you continue to read this part. Once you are connected, you can execute any Exchange PowerShell cmdlets.

To get mailbox information from Exchange Online, all you need to do is use the Get-MailBox cmdlet. Get-MailBox cmdlet supports various parameters. It is important to note that you must have necessary permissions to access mailboxes hosted at Exchange Online. Let’s start with a few simple examples of using Get-MailBox cmdlet before we explore advanced uses of the Get-Mailbox cmdlet.

To retrieve a list of all Mailbox from Exchange Online, execute below command in an elevated PowerShell window.

Get-MailBox

Tip: You will receive a warning message if your Exchange Organization at cloud hosts more than 1000 mailboxes as shown below:

 

Warning

WARNING: By default only the first 1000 items are returned. To change the number of items returned, specify the parameter “-ResultSize”. To return all items specify “-ResultSize Unlimited” (Note: Returning all items may take a very long time and consume a large amount of memory depending on the actual number of items). It is not recommended to store the results in a variable; instead pipe the results to another task or script to perform batch changes

The warning clearly indicates that the first 1,000 items will be returned if you run Get-MailBox without any parameters. In case you wish to see all mailboxes from Exchange Online, you need to add “-ResultSize” parameter as indicated in the command below:

Get-MailBox –Resultsize Unlimited

In case you would like to get a list of mailboxes from a particular organization, you will execute PowerShell command below:

Get-MailBox –OrganizationalUnit MyOrg

If you need to get the Last Logon Time for Office 365 mailboxes, what you can do is use Get-MailBoxStatistics PowerShell cmdlet along with the Get-MailBox cmdlet as shown in the command below:

Get-MailBox | Get-MailBoxStatistics

The above command generates a table that shows the Display Name and mailbox LastLogonTime of the Office 365 mailbox users.

You can always use “Export-CSV” cmdlet to export information to a CSV file as shown in the command below:

Get-MailBox | Get-MailBoxStatistics | Export-CSV C:\Temp\MailBoxLastLogonTime.CSV

Get-MailBox cmdlet can also help you get Office 365 users that have not logged onto their mailboxes. All you need to do is use the “Where” condition as shown in the below command:

Get-MailBox | Get-MailBoxStatistics | Where {-not $_.LastLogonTime}

Get-MailBox cmdlet and parameters

It is important to understand that the Get-MailBox cmdlet is available in both On-Premises Exchange Server installation and Exchange Online Service. Some parameters of Get-Mailbox cmdlet might not be available to one environment or the other. For example, “ReadFromDomainController” parameter is only available in On-Premises Exchange Server installations. Similarly, “IncludeInactiveMailbox” parameter can also be used when working with Exchange Online Service. There are a few parameters that are common. For example, “SortBy” parameter is available in both On-Premises Exchange Server installation and Exchange Online Service. We will discuss Get-MailBox parameters in details and provide some more examples of the Get-MailBox cmdlet in next and subsequent parts of this article series.

Coming next

In this part, we provided an overview of Get-MailBox PowerShell cmdlet and a few examples to get mailbox information from Office 365 Exchange Online Service.

There are several parameters supported by the Get-MailBox cmdlet. In the next part of this article series, we will review some useful parameters and also continue to provide more examples on the use of Get-MailBox PowerShell cmdlet.

If you would like to read the other parts in this article series, here are the links:

Part 1, Part 2, Part 3, Part 4, Part 5, Part 6, Part 7, Part 8, Part 9, Part 10, Part 11, Part 12.

About The Author

Leave a Comment

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

This site is protected by reCAPTCHA and the Google Privacy Policy and Terms of Service apply.

Scroll to Top