BlogFirst lesson
Sign Up

Connect PowerShell to Exchange Online

Connect to Exchange Online via PowerShell
Connect to Exchange Online via PowerShell

What’s Exchange Online?

Exchange Online is Microsoft’s hosted email for businesses. It’s the industry-leading cloud solution adopted by small businesses and fortune 500 companies. Microsoft Exchange Online provides the benefits of a cloud-based email service with the robust capabilities of an on-premises server deployment. Simply put, Microsoft will store, manage, and secure your businesses email for a low monthly cost. If you don’t find Exchange Online click here to view the Office 365 plans.

What’s PowerShell?

“Windows PowerShell is a Windows command-line shell designed especially for system administrators. Windows PowerShell includes an interactive prompt and a scripting environment that can be used independently or in combination.

Unlike most shells, which accept and return text, Windows PowerShell is built on top of the .NET Framework common language runtime (CLR) and the .NET Framework, and accepts and returns .NET Framework objects. This fundamental change in the environment brings entirely new tools and methods to the management and configuration of Windows.”

PowerShell can be accessed on most modern Windows computers by using the taskbar and searching for PowerShell.

What’s Exchange Online’s PowerShell?

Office 365 is a suite of clouds and services bundled into one package. Connecting to Exchange Online’s PowerShell will allow you to manage the email portion of your Office 365 tenant. You’ll need to connect to a different cloud service to access other portions of your Office 365 tenant.

One-Time Setup

  1. 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 (a Windows PowerShell window you open by selecting Run as administrator):
Set-ExecutionPolicy RemoteSigned

2. Download the following script: Connect-ExchangeOnline.

3. Unblock the script by right-clicking and clicking Unblock > Apply.

Connect-ExchangeOnline Powershell Properties

How to Connect to Exchange Online PowerShell

The script can be ran two different ways. You can run the script with the username and password directly inline or run the script without parameters and the PowerShell script will prompt for username and password.

Option 1: Run script with username and password inline

.\Connect-ExchangeOnline.ps1 AdminPassword123

Option 2: Run script with username and password prompt

connecting to exchange online via PowerShell

How to Disconnect from Exchange Online PowerShell

To disconnect the session you can close the PowerShell window and the session will expire or run the script with the disconnect switch.

.\Connect-ExchangeOnline.ps1 -disconnect
disconnecting from Exchange Online PowerShell

You’re now connected and can manage Exchange Online using PowerShell. The script will import the commands you can run. Microsoft has great documentation for each command. The easiest way to find the commands is Google.

For example, to get the mailboxes you run the following:


Follow me on Medium for more Office 365 information.