How to Connect to Exchange Online Using PowerShell?

In this article, we will show you how to install the Exchange Online PowerShell V2 (EXO V2) module and connect to Exchange Online. You can manage your Exchange Online tenant using the Exchange Admin Center (EAC) GUI or PowerShell. The Exchange Online PowerShell V2 module is used for connectivity and Exchange Online management. You can use EXO V2 module to connect to your Exchange Online in Microsoft 365 environment to manage settings, create/delete/modify mailboxes.

The EXO V2 module can be installed online from the PowerShell gallery, but you must have Windows PowerShell 5.1 or higher installed on your computer.

Hint. By using the REST API, EXO Module V2 is much faster and more reliable than the previous version of the Exchange Online PowerShell module (v1).

The new EXO V2 module supports Modern Authentication. This means you can connect to an Exchange Online tenant using MFA or non-MFA enabled account.

Note. Microsoft recommends enabling Multifactor Authentication for all Admin accounts. Basic EXO authentication will be decommissioned in 2021.

Installing the Exchange Online PowerShell V2 Module

Before installing the EXO V2 module, you need to change the settings for the PowerShell script execution policy. Open a PowerShell console as an administrator and run the command:

Set-ExecutionPolicy RemoteSigned

Confirm the change to the execution policy setting by pressing Y > Enter.

READ ALSO  Office 365 - "This message could not be sent. Try sending the message again later"

exchange online powershell

Close your current PowerShell console and start a new one:

start powershell.exe;exit

Now you need to install the PowerShellGet module:

Install-Module PowershellGet –Force

Confirm the import of the NuGet provider.

Now you can install the EXO V2 module:

Install-Module -Name ExchangeOnlineManagement

connect to exchange online powershell

To check which version of the EXO V2 module is installed, run the command:

Get-Module ExchangeOnlineManagement| ft name,version

In our case, the version is ExchangeOnlineManagement 2.0.3 is installed.

There are 17 cmdlets available in this version of the module. To list the available cmdlets, run the command:

Get-command -Module ExchangeOnlineManagement

connect exchange online powershell

The following cmdlets are available for managing Exchange Online:

  • Connect-ExchangeOnline;
  • Connect-IPPSSession;
  • Disconnect-ExchangeOnline;
  • Get-WrappedCommand;
  • IsCloudShellEnvironment;
  • UpdateImplicitRemotingHandler;
  • Get-EXOCasMailbox;
  • Get-EXOMailbox;
  • Get-EXOMailboxFolderPermission;
  • Get-EXOMailboxFolderStatistics;
  • Get-EXOMailboxPermission;
  • Get-EXOMailboxStatistics;
  • Get-EXOMobileDeviceStatistics;
  • Get-EXORecipient;
  • Get-EXORecipientPermission;
  • Get-UserBriefingConfig;
  • Set-UserBriefingConfig.

Hint. Please note that EXO V2 has changed the comnadlet names from Exchange Online PowerShell v1. For example, Get-EXOMailbox is used instead of Get-Mailbox, or Get-EXOMailboxStatistics is used instead of Get-MailboxStatistics, etc.

If you want to update a module, run the command:

Update-Module ExchangeOnlineManagement

Connect to Exchange Online with EXO PowerShell Module V2

To import the EXOv2 module into the PoSh current session, run the command:

Import-Module ExchangeOnlineManagement

If you are using an MFA (Multi-Factor Authentication) enabled administrator account, use the following cmcommand to connect to the Exchange Online:

Connect-ExchangeOnline -UserPrincipalName admin@theitbros.com

connect to exchange online

Enter your account password, then enter your verification code received in SMS and click Verify.

READ ALSO  Moving Exchange Mailboxes to Another Database

exchange online powershell module

If you are using a non MFA enabled account, use the following commands to connect to Exchange Online:

# Enter your Office 365 admin credentials

$Creds = Get-Credential

# Connect to Exchange Online under saved credentials

Connect-ExchangeOnline -Credential $Creds

powershell connect to exchange online

When you connect to Exchange Online, a banner appears in PowerShell listing the new cmdlets. To hide this banner, use the command:

Connect-ExchangeOnline -UserPrincipalName admin@theitbros.com -ShowBanner:$false -ShowProgress $true

You can now manage your Exchange Online mailboxes using PowerShell. For example, to get information about the d.brinkman mailbox, run the command:

Get-EXOMailbox d.brinkman@theitbros.com

To close a remote PowerShell session from Exchange Online, use the cmdlet:

Disconnect-ExchangeOnline -Confirm:$false
Cyril Kardashevsky

Leave a Reply

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

This site uses Akismet to reduce spam. Learn how your comment data is processed.