Connect to Exchange Online PowerShell

In this article we will learn how to connect to Exchange Online PowerShell to run commands to manage Exchange Online tasks as administrator. You will learn how to install Exchange Online PowerShell module, how to import Exchange Online PowerShell module, and how to connect to Exchange Online PowerShell as delegated admin.

Why you should use Exchange Online PowerShell

In today’s digitally-driven world, businesses rely heavily on efficient communication and collaboration tools to streamline their operations. Microsoft Exchange Online, a part of the Microsoft 365 suite, is one such powerful tool that facilitates email communication, calendaring, and contacts management. While the web interface provides a user-friendly experience for managing Exchange Online, there are times when administrators require more control and automation, which is where PowerShell comes into play.

PowerShell, Microsoft’s command-line shell and scripting language, offers administrators the ability to manage Exchange Online efficiently and at scale. By leveraging Exchange Online PowerShell, administrators can perform a wide range of tasks, from mailbox management to configuring mail flow rules, all with just a few lines of code.

Running scripts is disabled on this system

Before you start running below commands, please ensure that you are not restricted to run PowerShell scripts or commands. To verify, open Windows PowerShell as administrator, and run below command:

PowerShell
Get-ExecutionPolicy

The above command should display output as Unrestricted.

If you are getting an error “Running scripts is disabled on this system” or “cannot be loaded because running scripts is disabled on this system“, run below command in Windows PowerShell:

PowerShell
Set-ExecutionPolicy -ExecutionPolicy RemoteSigned -Scope CurrentUser

On the prompt, type Y and hit Enter.

Install Exchange Online PowerShell module

To install Exchange Online PowerShell, make sure you have opened Windows PowerShell as administrator and run below command:

PowerShell
Install-Module -Name ExchangeOnlineManagement

Import Exchange Online PowerShell module

After you have installed Exchange Online PowerShell module, you need to import it. Run below command in same Windows PowerShell:

PowerShell
Import-Module ExchangeOnlineManagement

Connect to Exchange Online PowerShell

Finally, it is time to connect to Exchange Online PowerShell. Run below command in the same PowerShell window:

PowerShell
Connect-ExchangeOnline -UserPrincipalName "UPN of Global Administrator"

In the above command, specify the user name of a global admin and run it.

PowerShell
Connect-ExchangeOnline -UserPrincipalName "[email protected]"

On the authentication prompt, type password for the global admin account, and click Sign in.

4

That is it! You are connected to Exchange Online.

Connect to Exchange Online PowerShell delegated admin

As an administrator you can connect to another Office 365 tenant as delegate. To achieve this you would require credentials of another tenant’s global administrator.

To connect to Exchange Online PowerShell as delegated admin, run below PowerShell command:

PowerShell
Connect-ExchangeOnline -DelegatedOrganization "UPN of other tenant's global admin"

On the authentication prompt, type the password and click Sign in.

Conclusion

In tis article you learnt how to connect to Exchange Online PowerShell module. You might like our other articles on How to connect to Graph PowerShell, Manage Office 365 licenses using Graph PowerShell and Manage Office 365 users using Graph PowerShell.

If you found this article helpful and informative, please share it within your community and do not forget to share your feedback in the comments below.

Please join us on YouTube for the latest videos on the Cloud technology and join our Newsletter for the early access of the articles and updates.

Happy Scripting!!