Getting started with the Exchange Online Management v2 PowerShell Module

Like many things in Microsoft 365 (formerly Office 365), a lot of the advanced and bulk operations aren’t possible in the standard web interface, and instead rely on the extensibility of PowerShell. Managing Exchange Online environments is no different, and while the Exchange Online Admin Center is mature and powerful, there are still a large number of configuration settings only possible via PowerShell.

The Exchange Online PowerShell V2 module (abbreviated ‘EXO V2 module’) is the replacement to the previous PowerShell module and simplifies the connectivity, removing the need to establish remote PowerShell Sessions manually and replacing it with modern authentication that works with Multi-Factor Authentication (MFA). Witht he new v2 module, you can connect and manage all Exchange-related PowerShell environments in Microsoft 365: Exchange Online PowerShell, Security & Compliance PowerShell, and standalone Exchange Online Protection (EOP) PowerShell.

Okay, but what is PowerShell?

Okay, most readers will probably already know this, but I thought I’d cover it for any new admins out there that stumble across my blog and struggle to make sense of all of the Docs out there. PowerShell, as the name says, is a powerful shell, created initially for Windows. In computer science, a shell is a user interface that gives you access to various services of an operating system, primarily used for purposes such as task automation and configuration management. Other examples you may have heard of include but are not limited to: Bash on Unix/Linux Bash, Terminal on MacOS, Command Prompt which is also in Windows, and more. The first version of PowerShell was released in November 2006 for Windows XP, Windows Server 2003 and Windows Vista, and has been included by default in every version of Windows 10 (and some earlier releases). You can access PowerShell, and it’s ‘development environment’ named ISE, from your Start Menu by typing PowerShell.

Another benefit of PowerShell is that it is extensible, and by using Modules, can be extended to provide management of a number of products, features and services. Today, we will be running PowerShell as Administrator so that we can download the module we need for managing Exchange Online.

Obtaining the required PowerShell Module

While it’s possible to download standalone installers for PowerShell modules, what we want to do today is obtain the Exchange Online Management module directly from the built in Microsoft PowerShell Gallery (PSGallery). To get started:

  1. Open a PowerShell window, making sure that you use the Run as Administrator option. We need to elevate this initial window because we are going to install a new module, and this will require the permission to download and install the module.
  2. We’ll start by showing what modules we have installed already, as we could switch the following command to an update instead of install if the required modules are already installed. Type the following command and press enter to see what we have available:

    Get-InstalledModule

    The module we need in this case, is ‘ExchangeOnlineManagement’, which is v2.0.4 at the time of writing.
  3. Next, type one of the following command into the PowerShell prompt and press enter, depending on whether you already have an older version of the required module or not:

    Install-Module -Name ExchangeOnlineManagement

    Update-Module -Name ExchangeOnlineManagement

    At this point, especially if you haven’t used PowerShell or installed modules before, you will likely have a few prompts that you need to accept. First, you will see a prompt explaining that you will need the NuGet provider in order to interact with the PSGallery, so press enter (or type “Y” then press enter) to accept and proceed with that installation; Next, you will likely be informed that you are installing the modules from an untrusted repository and asked to accept this. This is normal as the default PSGallery isn’t trusted out of the box, so type “Y” and press enter to accept this to begin the download of the required PowerShell module.
  4. After a few seconds, the installation should be completed and you will return to the PowerShell prompt. At this time, you can issue the same command as above to see the module we installed: Get-InstalledModule

    This time we should see that the General Availability (GA) release of Exchange Online PowerShell V2 module is installed, and should be at least v2.0.4. Using the v2 module is important, as not only will this contain the most updated commands for Exchange online management, but it greatly simplifies the creation of the remote management shell while also allowing Multi-Factor Authentication (MFA) as part of the sign-in process.

Connecting to Exchange Online Management

The next step should be obvious, it’s time to put the module to use and connect to Exchange Online Management. However, depending on your device configuration and security policies, you may find that things don’t work quite like the various Docs you will find. So if you’ll excuse another paragraph and a few more bullet points, I’ll explain this process. Ultimately, the end goal is to issue the connect command and have this prompt for Global or Exchange Administrator credentials to make the needed connection, so we’ll try that first to see if it works.

  1. In your PowerShell window – or open a new one if you don’t have one from the above steps – attempt the following command:

    Connect-ExchangeOnline

    If you see yellow text describing the module and receive a popup window to enter credentials, then you’re not restricted and are able to skip to the next section. If you see red error text that suggests you need to import the module, then there are restrictions in place and you should go to the next step.
  2. To keep workstations safe, especially as PowerShell is installed by default, some sites implement policies to restrict the ability to run unsigned scripts, with some going as far as blocking all scripts. Check your current policy value using this command:

    Get-ExecutionPolicy

    If you were blocked in step 1, you likely have a value of ‘Restricted’. Luckily, you don’t actually need to create exceptions to these policies, you can simply bypass them for a short period of time by entering the following PowerShell command:

    Set-ExecutionPolicy -Scope Process -ExecutionPolicy Unrestricted

    This will allow the single PowerShell window – the current process – to run scripts and modules in unrestricted mode. You can confirm the change by running the Get-ExecutionPolicy command again.
  3. With PowerShell execution now unblocked, you should be able to import the PowerShell module without error. Use the following command to test that and prepare for the next step:

    Import-Module -Name ExchangeOnlineManagement

    If nothing errors out and you end up at a new line, then the module was successfully loaded and you’re ready to connect.
  4. Finally, issue the connect command as below:

    Connect-ExchangeOnline

    At this point, you should be be asked to securely provide your Global or Exchange Administrator credentials, and complete any Multi-Factor Authentication (MFA) and Conditional Access requirements in order to complete the process.

What’s next?

Now that you’re connected, return to the PowerShell prompt and you should be able to execute any number of Exchange Online commands and start your EXO management journey via PowerShell. I’ll be writing a few blog posts that discuss Plus Addressing, Address Book Policies, and much more, and this post will serve as the ‘how to get started?’ for those, so stick around and find out more.

Comments are closed.

Create a website or blog at WordPress.com

Up ↑

%d bloggers like this: