Use the Exchange Online PowerShell V2 module

The Exchange Online PowerShell V2 module (abbreviated as the EXO V2 module) enables admins to connect to their Exchange Online environment in Office 365 to retrieve data, create new objects, update existing objects, remove objects as well as configure Exchange Online & its features.

Tip

If you have any feedback/concern or facing any issues with EXO V2 module, please send an email to exocmdletpreview[at]service[dot]microsoft[dot]com.

What's new in the EXO V2 module?

The Exchange Online PowerShell V2 module contains a small set of new cmdlets that are optimized for bulk data retrieval scenarios (think: thousands and thousands of objects). It also contains the 700 or more older remote PowerShell cmdlets baked into the same module. Note that after you install the EXO V2 module from the PowerShell Gallery, you only see new cmdlets in the module. You'll see the older remote PowerShell cmdlets after you create a session to connect to your Exchange Online environment. All the cmdlets in the V2 module use Modern auth for authentication. You can't use Basic auth in the EXO V2 module.

The new cmdlets in the EXO V2 module are meant to replace their older, less efficient equivalents. However, the original cmdlets are still available in the EXO V2 module for backwards compatibility.

The new cmdlets in the EXO V2 module are listed in the following table:

New cmdlet in the EXO V2 module Older related cmdlet
Connect-ExchangeOnline Connect-EXOPSSession
or
New-PSSession
Get-EXOMailbox Get-Mailbox
Get-EXORecipient Get-Recipient
Get-EXOCASMailbox Get-CASMailbox
Get-EXOMailboxPermission Get-MailboxPermission
Get-EXORecipientPermission Get-RecipientPermission
Get-EXOMailboxStatistics Get-MailboxStatistics
Get-EXOMailboxFolderStatistics Get-MailboxFolderStatistics
Get-EXOMailboxFolderPermission Get-MailboxFolderPermission
Get-EXOMobileDeviceStatistics Get-MobileDeviceStatistics

Install and maintain the Exchange Online PowerShell V2 module

You can download the EXO V2 module from the PowerShell gallery here.

What do you need to know before you begin?

Install the EXO V2 module

To install the EXO V2 module for the first time, run the following commands:

  1. On your local computer, run the following command from an elevated Windows PowerShell session (a Windows PowerShell window you open by selecting Run as administrator):

    Install-Module PowershellGet -Force
    
  2. Windows PowerShell needs to be configured to run scripts, and by default, it isn't. To require all PowerShell scripts that you download from the internet are signed by a trusted publisher, run the following command in an elevated Windows PowerShell window:

    Set-ExecutionPolicy RemoteSigned
    

    Notes:

    • You need to configure this setting only once on your computer.

    • If you don't do this step, you'll receive the following error when you try to connect:

      Files cannot be loaded because running scripts is disabled on this system. Provide a valid certificate with which to sign the files.

  3. From an elevated Windows PowerShell session and run the following command:

    Install-Module -Name ExchangeOnlineManagement
    

    Enter Y to accept the license agreement.

Update the EXO V2 module

If the EXO V2 module is already installed on your computer, you can run the following commands to see the version that's currently installed and update it if necessary.

  1. To see the version of the EXO V2 module that's currently installed, run the following commands:

    Import-Module ExchangeOnlineManagement; Get-Module ExchangeOnlineManagement
    
  2. Run the following command to update the EXO V2 module to latest version that's available in the PowerShell Gallery:

    Update-Module -Name ExchangeOnlineManagement
    

    Enter Y to accept the license agreement.

  3. To confirm that the update was successful, run the following commands:

    Import-Module ExchangeOnlineManagement; Get-Module ExchangeOnlineManagement
    

Uninstall the EXO V2 module

To uninstall the module, run the following command:

Remove-Module ExchangeOnlineManagement

Tip

Having problems? Ask for help in the Exchange forums. Visit the forums at: Exchange Online, or Exchange Online Protection.

Connect to Exchange Online using the EXO V2 module

Note

If your account uses multi-factor authentication (MFA), skip the first step (the Get-Credential cmdlet doesn't support MFA enabled accounts).

  1. On your local computer, open a Windows PowerShell window and run the following command:

    $UserCredential = Get-Credential
    

    In the Windows PowerShell Credential Request dialog box, type your work or school account and password, and then click OK.

  2. Run one of the following commands:

    • Accounts without MFA enabled:

      Connect-ExchangeOnline -Credential $UserCredential -ShowProgress $true
      
    • Accounts with MFA enabled: Replace <UPN> with your account in user principal name format (for example, navin@contoso.com) and run the following command:

      Connect-ExchangeOnline -UserPrincipalName <UPN> -ShowProgress $true
      

For detailed syntax and parameter information, see Connect-ExchangeOnline.

What's new in the EXO V2 module?

Properties and property sets

The output of traditional Exchange Online cmdlets returns all possible object properties, including many properties that are often blank, or aren't even required in many scenarios. Returning a large number of blank and unnecessary properties causes degraded performance (more server computation and added network load). The full complement of properties are rarely required in the cmdlet output.

The EXO V2 module cmdlets have categorized output properties. Instead of giving all properties equal importance and returning them in all scenarios, we've categorized specific related properties into property sets. Simply put, these property sets are buckets of two or more related properties on the cmdlet.

Property sets are controlled by the following parameters on the EXO V2 module cmdlets:

  • PropertySets: This parameter accepts one or more available property set names separated by commas.

    This example returns the properties that are available in the Archive and Custom property sets:

    Get-EXOMailbox -PropertySets Archive,Custom
    
  • Properties: This parameter accepts one or more property names separated by commas.

    This example returns the specified properties:

    Get-EXOMailbox -Properties LitigationHoldEnabled,AuditEnabled
    

    Note: Cmdlets that only return a small number of output properties don't have the PropertySet or Properties parameters.

You can use PropertySets and Properties in the same command. For example:

Get-EXOMailbox -Properties IsMailboxEnabled,SamAccountName -PropertySets Delivery
Get-EXOCASMailbox -Properties EwsEnabled, MAPIBlockOutlookNonCachedMode -PropertySets ActiveSync

We've also included a Minimum property set (or minset) in the available property sets that includes a bare minimum set of properties for the cmdlet output.

  • If you don't use the PropertySets or Properties parameters, you automatically get the properties that are included in the Minimum property set.

  • If you use the PropertySets or Properties parameters, you you only get the specified properties.

Either way, the cmdlet output will contain far fewer properties, and the time it takes to return those results will be much faster.

This example returns the properties in the Minimum property set for the first ten mailboxes.

Get-EXOMailbox -ResultSize 10

In contrast, the same Get-Mailbox cmdlet would return at least 230 properties for the same ten mailboxes.

For details about the property sets that are available in EXO V2 module cmdlets, see Property sets in Exchange Online PowerShell V2 cmdlets or the individual EXO V2 module cmdlet reference topics.

EXO cmdlets also provide a way to retreive all properties for an object by using the ProperySets parameter with the value All.

The following example returns all properties for the 10 mailboxes:

Get-EXOMailbox -ResultSize 10 -PropertySets All

Note

We highly discourage using the PropertySets parameter with the value All because it slows down the cmdlet and reduces reliability. Always use the PropertySets and Properties parameters to retreive only the requires properties.