Powershell function for Exchange online

Working as a consultant for multiple customers forces us to connect multiple times a day to different Exchange Online management shell’s. Everyone has his own way to save the connection command for the Exchange Online PowerShell. I had the command always saved in a ready to use Notepad document.

However, since I am always using the same devices for work, we created a small PowerShell function which makes it easier and faster to connect to customers Exchange Online environments.


The Function

How to use the Function

Copy the code into your PowerShell, or PowerShell ISE session and run it. Then type Connect-ExchangeOnline and have fun with it.

If we want to make the function permanently available so it’s is there every time we start PowerShell, we have to create a folder in C:\Program Files\WindowsPowerShell\Modules. This folder we name Connect-ExchangeOnline. After that we save the code (our function) as a .psm1 file in that folder. 

To see an example, have a look on the picture below:



Connect to Exchange online

I want to show you first what we are going to achieve.

After starting the default Windows PowerShell cmdlet, we simply hit the command Connect-ExchangeOnline and we get prompted to the logon windows for our credentials. Depending on which credentials we are using here, we are going to be connected to our environment.


If we are managing multiple Exchange online instances (As CSP for example) we can run the following command:



Get the function

This function can easily be copied out from this article or downloaded from the Microsoft Technet by following the link below:





Photo by Malcolm Lightbody on Unsplash

Leave a Reply

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