Connecting to an Exchange Online PowerShell session is not a complicated task. There are several Microsoft guides that walk you through this, but if you are someone who connects frequently to Exchange Online, the process can be simplified even further with the addition of a PowerShell Custom function to your PowerShell Profile.

Click here to collapse the What is a PowerShell Profile section and skip straight to the instructions for setting up your PowerShell custom functions.

What is a PowerShell Profile?

A PowerShell profile is a PowerShell script that runs automatically when a new PowerShell session is started. PowerShell profiles can be used to configure your PowerShell environment the way you like it, or to load custom functions for use in your PowerShell administration tasks.

You can check to see if you already have a PowerShell profile by opening PowerShell (NOT as admin, as your user) and running the following command:

  • If it returns False then you do not have a profile.
  • If a path and file name is returned, then you do have an existing profile.

Creating your PowerShell Profile

If you do not have a PowerShell Profile and would like to create one, you can do so by running the following commands:

  • This will open the PowerShell ISE and allow you to paste in the functions you’d like to automatically load when you open PowerShell.

Adding the Connect-EXOnline Function via pre-built script

In order to make this as simple as possible, a PowerShell script is linked below that will automatically check if you already have a Profile and create one if not, then add the necessary functions to your new profile. If you already have a profile but do not have the functions, it will add them for you.

Run the script by extracting the zip file, opening a PowerShell session (Not as Admin) changing directory to the extracted folder containing the AddEXOnlineProfileFunctions.ps1 file, and running the command below:

  • It should display a result message in green text letting you know it was successful.

If you’re curious what that PS1 file contains, here is the raw code:

Manually Install the Connect-EXOnline functions

To add the Connect-EXOnline function, we will first open our Profile via the steps above and paste in the following code:

Save ISE and close out, then open a new PowerShell session and run the following command:

  • A dialog will popup asking for your Office 365 admin credentials. After a short wait the connection will be established and you can run cmdlets such as Get-Mailbox to list the mailbox users in Exchange Online for your Office 365 tenant.