Active Directory & Office 365 Reporting Tool

How to Connect to Exchange Online using Powershell. Have you ever needed to manage Exchange Online and felt that the web based admin center was too limited? All in all, PowerShell offers you a more robust option, and in this article, I show you how to connect to Exchange Online using PowerShell and manage it with available cmdlets.

Before you successfully connect to Exchange Online, you must ensure that your PC meets some requirements. So, in the first section of this article, I walk you through the steps to prepare to connect to Exchange Online. 

Then, follow the steps in my second session to install the module and make the connection to Exchange Online. 

Finally, I will share some commands you can run to manage Exchange Online using PowerShell.  

Requirements for the Exchange Online PowerShell Module

This section describes the actions you must take to ensure you successfully connect to and download Exchange Online modules.

1. Run PowerShell as Administrator: Search “PowerShell” (without the quotes). Then, right click Windows PowerShell and select “Run as administrator.”

2. Set PowerShell ExecutionPolicy to RemoteSigned: By default, Windows PowerShell is configured to deny running commands from modules downloading from the internet. 

Therefore, to be able to run commands from the Module you’re about to download, run the command below:

					powershell.exe -ExecutionPolicy RemoteSigned

3. Check that Basic authentication is turned on in WinRM: Run the first command below to enable WinRM. Then, run the second command to confirm that Basic authentication is enabled for WinRM on your PC. 

The first command prompts you to confirm that you want to Start the WinRM Service. Type Y and press Enter. 

					winrm quickconfig

					winrm get winrm/config/client/auth

As shown in the screenshot below, the second command above displays your computer’s WinRM “Auth” status. The point I labeled (4) shows “Basic = true.” 

If yours shows “false” it means that Basic authentication is disabled, and you need to enable it. 

If you need to enable Basic authentication run the command below:

					winrm set winrm/config/client/auth '@{Basic="true"}'

Connect to Exchange Online using PowerShell

When you’ve completed the steps in the previous section, the next step is to install the Exchange Online module on your computer. Follow the steps below to complete this part of the task:

1. Install the Exchange Online PowerShell module by running the command below. The command may take a short while to complete. 

PowerShell will return to its prompt when the command is completed, and the module is installed on your computer – see my screenshot below. 

					Install-Module -Name ExchangeOnlineManagement

2. To confirm that the ExchangeOnlineManagement PowerShell module has installed successfuly on your computer, run the command below:

The above command returns all the cmdlets in the ExchangeOnlineManagement module, including the Connect-ExchangeOnline cmdlet – which you require to connect to Exchange Online.

					Get-Command -Module ExchangeOnlineManagement

3. Next, make the connection to Exchange Online by running the command below:

					Connect-ExchangeOnline -UserPrincipalName Username@DomainName.com

Replace Username@DomainName.com with your Office 365 username in the same UPN format. When you press Enter, PoweerShell displays a password window.

Enter your password and click Sign in.

If PowerShell authenticates successfully and connects to Exchange Online, you receive some messages similar to the one in my screenshot below: 

Improve your Active Directory Security & Azure AD with Office 365 Reporting Tool

Try us out for Free, Access to all features. – 200+ AD Report templates Available. Easily customise your own AD reports.

Common Exchange Online PowerShell Commands

Now that you’ve connected to EXO PowerShell, you run commands and perform some tasks like managing mailboxes.

If you’re not sure about the command you require to perform the task you intend to, start by running the Get-Module command below:

					(Get-Module ExchangeOnlineManagement | Select-Object ExportedCommands).ExportedCommands

The command displays the cmdlets in the module. 

In the next two sub-sections, I discuss some of the common cmmandlets available in the ExchangeOnlineManagement module.

Example 1: Get-EXOMailbox

The Get-EXOMailbox command is arguably the simplest command in this module. If you run the command without any parameters or filters, it returns all EXO mailboxes in your account. 

If your Exchange Organisation has a large number of users, I do not recommend running this command without any filters, as it may take longer than necessary to return all the mailboxes. 

In the screenshot below, I have shown one mailbox in my Office 365. I also highlighted important properties of the mailboxes returned by the command – RecipientTypeDetails.

The RecipientTypeDetails property shows the type of mailbox. In this instance, it is a shared mailbox. 

Use this property to return all shared mailboxes, for example. If you want to return all shared mailboxes, here is a sample command: 

					Get-EXOMailbox | Where-Object {$_.RecipientTypeDetails -eq "SharedMailbox"}

Example 2: Get-ConnectionInformation

Another useful command, which you may require most times, is the Get-ConnectionInformation command. As the name of the cmdlet sounds, it displays information about your Exchange Online connection. 

Here is the result of the command for my connection.

As seen in the screenshot above, the command displays some useful information about your connection which you may use to perform additional queries. One good example if your TenantID which you may require in some commands. 

Example 3: Update Exchange Online PowerShell Module

From time to time, it is a good idea to update the modules on your computer, and this module is not an exception. To update Exchange Online run the command below:

					Update-Module -Name ExchangeOnlineManagement

How To Disconnect from Exchange Online PowerShell Connection

When you finish performing the task you intend to perform in your EXO organization, disconnecting is good practice. To disconnect, run the simple command below:


PowerShell prompts you to confirm the action when you run the command. To confirm that you want to disconnect PowerShell from Exchange Online, press the Enter key on your keyboard. 

If you want to disconnect from EXO PowerShell without PowerShell prompting you for confirmation, run the modified command below:

					Disconnect-ExchangeOnline -Confirm:$false

How to Connect to Exchange Online using Powershell Conclusion

Any Windows SysAdmin that wants to stay on top of their game must be comfortable with PowerShell. From my personal experience, PowerShell empowers you in ways that GUI tools do not. 

In this guide, I have demonstrated one benefit of PowerShell – managing Exchange Online. Well, installing the module is the first step to managing EXO with PowerShell.

Then, you use the Connect-ExchangeOnline cmdlet – one of the cmdlets in the ExchangeOnlineManagement module – to connect to Exchange Online PowerShell. 

Once you’re connected to EXO, you display the cmdlets available in the EXO module by running the Get-Module or Get-Command commands. 

From this point, Exchange Online is your oyster – made possible by the one and only PowerShell! 


Try InfraSOS for FREE

Invite your team and explore InfraSOS features for free

Victor Ashiedu

Victor Ashiedu

Victor is an IT pro based in Manchester, UK. With over 22 years of experience managing Windows Server, Active Directory, and Powershell, and 7 years of expertise in Azure AD and Office 365, he's a seasoned expert in his field. When he's not working, he loves spending time with his family - a wife and a 5-year-old. Victor is passionate about helping businesses succeed in today's fast-changing tech landscape.

Leave a comment

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