How to Install Exchange Online PowerShell Module
Managing email communication processes can be a real challenge for medium and big-sized businesses.
Although Microsoft Exchange offers different management features, streamlining and managing administrative tasks is easier by using the Exchange Online PowerShell Module.
The Exchange Online PowerShell Module allows administrators to easily manage Exchange Online Environments using command lines.
In this blog post, we’ll simplify the installation process so you can learn how to install Exchange Online PowerShell module by following five quick steps.
Benefits of Installing the Exchange Online PowerShell Module
The Exchange Online PowerShell module allows administrators to manage their environments more easily, efficiently, and effectively.
Although it is possible to use the Exchange Admin Center (EAC) to manage Exchange Online, using the PowerShell module brings way more advantages and benefits to administrators, such as the following:
- Helps you in bulk-data retrieval scenarios and allows you to create mailboxes in bulk just by using cmdlets on PowerShell.
- It allows you to automate tasks that would otherwise be time-consuming, such as the creation of new users or the deletion of Microsoft Exchange Online objects.
- If things don’t go as planned, the PowerShell Module can help you with bug fixes by identifying what’s wrong with a certain mailbox or account.
What Do You Need for Connecting to Exchange Online PowerShell?
In order to install PowerShell and connect to the Online Module, there’s a series of requirements that must be met beforehand:
- A Microsoft Office 365 account with valid Exchange Licenses enabled.
- An Exchange Administrator Role and valid credentials to access the Office 365 account.
- A computer running Windows 7 or later.
- The latest PowerShell version installed (7.3.6).
How to Install Exchange Online PowerShell Module
To install the Exchange Online PowerShell module, we are going to use PowerShell cmdlets.
The process consists of enabling execution policies to run scripts, installing the PowerShell module, and then connecting to Exchange Online PowerShell V3. These are the five steps we need to follow.
Step 1: Set Windows PowerShell Execution Policy
We can’t install PowerShell scripts by default - this is the default behavior of PowerShell.
Therefore, we need to set the execution policy that will allow us to subsequently install Exchange Online PowerShell.
Open PowerShell on your computer, and let’s sign the execution policy, which, in theory, protects you from scripts that you don’t trust.
To set Execution Policy in PowerShell, use the following command:
“Set-ExecutionPolicy RemoteSigned” |
After implementing the command line, close and relaunch this PowerShell Window for the changes to take effect.
Now, we are going to install the PowerShellGet module on our system.
If, by any chance, you believe that the module is already installed, you can check it out by using the following cmdlet:
Get-InstalledModule -Name ExchangeOnlineManagement |
If the module hasn’t been installed before, you will see a message that says, “No match was found for the specified search criteria.”
In this case, move on to the following step to continue with the installation process.
Step 2: Set Up PowerShellGet Module
Now, we are going to set up the PowerShellGet module, which is the previous step to connecting to Exchange Online.
To execute these cmdlets, it is necessary to run PowerShell as an Administrator.
Type PowerShell on Windows search, right-click on the PowerShell icon, and select “Run as Administrator.”
Afterward, use the following command and press enter:
Install-Module PowershellGet -Force |
A message will pop up asking you for the newest NuGet Provider version. The exact message is the following:
“PS C:\> Install-Module PowershellGet -Force NuGet provider is required to continue PowerShellGet requires NuGet provider version '2.8.5.201' or newer to interact with NuGet-based repositories. The NuGet provider must be available in 'C:\Program Files\PackageManagement\ProviderAssemblies' or 'C:\Users\administrator.EXOIP\AppData\Local\PackageManagement\ProviderAssemblies'. You can also install the NuGet provider by running 'Install-PackageProvider -Name NuGet -MinimumVersion 2.8.5.201 -Force'. Do you want PowerShellGet to install and import the NuGet provider now? [Y] Yes [N] No [S] Suspend [?] Help (default is "Y"): Y |
You will be prompted to install NuGet Provider, so press Y and then Enter to install the latest NuGet Provider version.
Likewise, you may be asked to install the NuGet Provider from an untrusted repository - select “Yes” as this is entirely safe to do.
After using the import module cmdlet, it’s time to get our hands into the Exchange Online PowerShell module using the install-module cmdlet.
Step 3: Install the Exchange Online Management module
For this step, we are using the install-module cmdlet to finish the installation of the module after all permissions have been previously granted.
Open PowerShell again, and run the following command:
Install-Module -Name ExchangeOnlineManagement |
After running the command, the installation of the module will begin.
Keep in mind that the installation will take a few minutes, depending on the speed of your Internet connection, so wait for a few minutes and move on to the fourth step.
Step 4: Connect to Exchange Online PowerShell V3
Finally, after the module has been installed, it’s time to connect to Exchange Online PowerShell V3.
To do this, go to the PowerShell window, and run the following command:
Connect-ExchangeOnline -UserPrincipalName admin@mail.com |
The Connect-ExchangeOnline cmdlet will prompt you to sign into your Office account. Remember to replace admin@mail.com with the principal name of your administrator account before running the cmdlet.
Afterward, a sign-in window will appear. Here, simply type in your credentials in order to access your Exchange account.
If multi-factor authentication is enabled, you will need to type in the verification code for the current user account in order to continue.
Once you have successfully logged into the Exchange Online Module, you will receive the following message:
This V3 EXO PowerShell module contains new REST API backed Exchange Online cmdlets which doesn't require WinRM for Client-Server communication. You can now run these cmdlets after turning off WinRM Basic Auth in your client machine thus making it more secure. Unlike the EXO* prefixed cmdlets, the cmdlets in this module support full functional parity with the RPS (V1) cmdlets. V3 cmdlets in the downloaded module are resilient to transient failures, handling retries and throttling errors inherently. However, REST backed EOP and SCC cmdlets are not available yet. To use those, you will need to enable WinRM Basic Auth. |
This indicates that the connection to the Exchange Online PowerShell module has been successful.
It also means that, as you can see, you don’t need basic authentication in order to manage Exchange Online V3, as it supports certificate-based authentication (connecting to PowerShell after basic authentication is deprecated).
Alternatively, you can also download and install the module from the PowerShell Gallery (more info about the PowerShell Gallery here).
Step 5: Use Commands Available in the Exchange Online Environment
You have now installed and connected to the Exchange Online PowerShell module.
The Exchange Online Service allows you to run a series of rich cmdlets that allow you to perform otherwise time-consuming tasks within a few minutes or seconds.
This is a quick overview of the most important and used commands available in the Exchange Online PowerShell module:
Command | Explanation |
Set-Mailbox | Allows you to modify a mailbox that already exists. |
Remove-Mailbox | Let’s you delete a mailbox if necessary. |
Get-Mailbox | Retrieve mailbox information and set mailbox permissions if needed. |
Get-Mailboxstatistics | Returns information about the number of messages in a mailbox. |
Get-Recipient | Show information about a recipient, such as recipient type and email address. |
New-Mailbox | Create an entirely new mailbox as requested. |
In order to make the best out of the Exchange Online PowerShell module, make sure to check out these three relevant tips:
- Explain your PowerShell Script with comments before running it to keep track of the task.
- If you want to connect to the module faster, try disabling multi-factor authentication to accelerate the connection process.
- Keep the Exchange Online PowerShell Module updated - you can do this by running the following command on PowerShell: “Update-Module -Name "ExchangeOnlineManagement.”
How to Disconnect Remote PowerShell Session
After finishing with the Exchange Online Management module, you’ll typically want to disconnect the session in order to use a different tenant or free up resources.
To disconnect from your current PowerShell session, run the following command:
Disconnect-ExchangeOnline |
Running this command will remove the access token from the cache and local files, which allows you to start a brand-new session the next time you connect to the Exchange Online PowerShell module.
Summary: How to Install Exchange Online PowerShell Module
By installing and connecting to the Exchange Online PowerShell Module, you can manage your Exchange Online Organization using PowerShell’s cmdlets, which will save you a lot of time and resources.
Let’s summarize the process of installing the Exchange Online PowerShell module in three relevant points:
- Setting up policy permissions is crucial for running scripts on PowerShell. Likewise, downloading the required modules is necessary to continue the process.
- Install the module by using the install-module cmdlet. The module will download, which will allow you to establish an online connection with the server when you run PowerShell.
- Use connection-related cmdlets to establish a connection with the Exchange Online PowerShell Module. Try to keep MFA disabled to ensure a faster connection with the online module.
FAQ
Why Can’t I Install Exchange Online PowerShell Module?
If you are unable to install the Exchange Online PowerShell module, try to disable multi-factor authentication on your Office account, ensure that you are using the right credentials, and make sure you have all the permissions by checking execution policies again. Alternatively, try to reinstall the module by using the install-module cmdlet mentioned above from the beginning.