Connect To Exchange Online PowerShell

Coming back to my roots a little bit with this post. My most recent ones have been around technologies that I typically don’t handle, or write about. Feels good to come back to PowerShell and Exchange so that I can show you how to connect to Exchange online PowerShell.

Connect to Exchange Online using: Connect-ExchangeOnline

I also wrote this post on Medium, in case you prefer reading over there!

Introduction

I think it’s important to cover some of the groundwork that is required to answer this questions.

First of all, you’ll need to have PowerShell.

What is PowerShell, you say? PowerShell is often talked as the successor to the Windows Command Line or CMD. PowerShell is a command line tool and scripting language typically used create scripts for automating procedures.

Although, I have used it to make games in the past!

Connect To Exchange Online PowerShell - main image

Exchange Online from Microsoft is part of the Microsoft 365 and Office 365 suite of products. Best way to thing of this is that Exchange is the emailing product that allows the flow of emails and other services, Exchange Online is the management platform for Exchange.



Why PowerShell?

It is a fair question to ask: why use PowerShell when I can just use the Exchange admin console?

Well if you need to make a lot of changes to a lot of different mailboxes, then PowerShell is an awesome tool to prevent repetitive work in a graphical environment. Spending 30 minutes creating a script to automate the process is much better taking 2 days to make the changes manually. You don’t want to be pulling your hair out…

This is where the Exchange Online module for PowerShell comes in really handle, as it allows a much simpler way of executing commands.

In this article, I will also show you how to install the Exchange Online module.

Install Exchange Online Module

Okay, so before we can use the Exchange Online module, we need to actually install it. We’ll be installing the V2 of the PowerShell module using the below command, open an Admin PowerShell prompt and run:

Get-Module -ListAvailable -Name ExchangeOnlineManagement

Depending on what comes back, it should look similar to the screenshot below:

Connect To Exchange Online PowerShell - get the module from PowerShell

If you get the same output as the screenshot, then you can now install the module:

Install-Module -Name ExchangeOnlineManagement -Force

If you get a confirmation for the install, just press ‘Y‘.

Update Exchange Online Module

As a side-note, if you find that the Exchange Online module is already installed, you can update it by running the below command in an Administrator PowerShell prompt:

Update-Module -Name ExchangeOnlineManagement -Force

Connect To Exchange Online PowerShell

Now that the module has been installed, we can now connect to the Exchange Online infrastructure to start our automation process. In order to connect, all you need to run is:

Connect-ExchangeOnline

It’s that simple! There are so variables you could pass to this command but they typically aren’t needed or used. For example, you could specify a user account with the -UserPrincipalName flag and also remove the startup banner with -ShowBanner. I’ll put an example of these below in case you need them!

Connect-ExchangeOnline -UserPrincipalName flastname@example.com

Connect-ExchangeOnline -ShowBanner:$false
back of servers

Disconnect Exchange Online Module

After you’ve finished your work, you’ll need to disconnect from Exchange Online. Sessions do expire automatically, so you are technically ‘safe’ to just close the PowerShell window, but closing the EXO session is always the safest method.

I definitely recommend disconnecting the Exchange Online module if you are running this in an automated PowerShell script. Last thing you want is a bunch of scripts to run, leaving the EXO sessions open and potentially causing issues.

Thankfully, this is simple to do. You can disconnect using:

Disconnect-ExchangeOnline

FAQ

Conclusion

I hope this post made the method for installing and using the Exchange Online module for PowerShell simple. Once you start using this module more, you’ll quickly see how much time it can save you when performance repetitive admin tasks on your Exchange infrastructure.

I think it would be useful to also mention, that you can get a full list of all the available commands in the module by running the below:

Get-Command -Module ExchangeOnlineManagement

Additionally, when connecting to the EXO environment, you’ll also get a popup to enter your credentials and to enter any MFA authentication that might be setup. Don’t be alarmed, just enter your details as normal.

I hope you found this article useful!

Enjoy! 🎉

3 thoughts on “Connect To Exchange Online PowerShell”

  1. Russel Mulligan

    Hi!

    Is your website not making the sales that it should?

    We build highly branded shopify stores.

    Be your own boss, you want a BUSINESS, not a website only!
    The best value for your money (17k happy clients)
    We provide you with lifetime support!

    No sales in 30 days from our system? Get a full refund

    Come get your shopify site built for you and dominate your market.

  2. Hi,

    I just visited mharwood.uk and wondered if you’d ever thought about having an engaging video to explain what you do?

    Our videos cost just $195 for a 30 second video ($239 for 60 seconds) and include a full script, voice-over and video.

    I can show you some previous videos we’ve done if you want me to send some over. Let me know if you’re interested in seeing samples of our previous work.

    Regards,
    Joanna

  3. This was a really helpful guide! I appreciate the step-by-step instructions for connecting to Exchange Online PowerShell. It saved me a lot of time while setting things up. Looking forward to more insightful posts like this!

Leave a Comment

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

email popup image
Mark Harwood
NEVER miss a blog post again! Subscribe for email notifications whenever a new post is live!
Subscribe
NEVER miss a blog post again! Subscribe for email notifications whenever a new post is live!
No obligation call, message, or email
Contact form image
I'll Be In Touch Soon