skip to Main Content

Connect to Exchange Online PowerShell

Before you can connect to Exchange Online PowerShell, you need to install the Exchange Online Management module. After that, you can connect to Exchange Online PowerShell with or without MFA. Also, you can use Windows PowerShell, Windows PowerShell ISE, or Visual Studio Code and connect to Exchange Online PowerShell. In this article, you will learn how to connect to Exchange Online PowerShell step by step.

Install Exchange Online PowerShell V2 module

Before we can install Exchange Online PowerShell V2 module, we need to set up the system.

Configure PowerShell to install scripts

By default, we can’t install scripts. To require all PowerShell scripts that you download from the internet are signed by a trusted publisher, run PowerShell as administrator, and run the Set-ExecutionPolicy RemoteSigned cmdlet. Press Y and press Enter.

PS C:\> Set-ExecutionPolicy RemoteSigned

Execution Policy Change
The execution policy helps protect you from scripts that you do not trust. Changing the execution policy might expose
you to the security risks described in the about_Execution_Policies help topic at
http://go.microsoft.com/fwlink/?LinkID=135170. Do you want to change the execution policy?
[Y] Yes  [A] Yes to All  [N] No  [L] No to All  [S] Suspend  [?] Help (default is "N"): Y

Important: Close and re-open the elevated Windows PowerShell window to have the changes apply.

Install PowerShellGet module

Run PowerShell as administrator. Run the Install-Module PowershellGet -Force cmdlet. When asked to install NuGet provider, press Y and follow with Enter.

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

If you get an error that it’s unable to install, read the article Unable to install NuGet provider for PowerShell.

Install Exchange Online Management module

Install the Exchange Online Management module. Press Y and Enter.

PS C:\> Install-Module -Name ExchangeOnlineManagement

Untrusted repository
You are installing the modules from an untrusted repository. If you trust this repository, change its
InstallationPolicy value by running the Set-PSRepository cmdlet. Are you sure you want to install the modules from
'PSGallery'?
[Y] Yes  [A] Yes to All  [N] No  [L] No to All  [S] Suspend  [?] Help (default is "N"): Y

Connect to Exchange Online PowerShell

Connect with your admin account to Exchange Online. Run the Connect-ExchangeOnline cmdlet.

PS C:\> Connect-ExchangeOnline -UserPrincipalName admin@exoip.com

In the sign-in window that opens, enter your password, and then click Sign in.

If MFA is enabled, a verification code is generated and delivered based on the verification response option that’s configured for your account. For example, a text message or the Azure Authenticator app on your mobile phone.

Connect to Exchange Online PowerShell MFA

After the verification succeeds, you will get back to the PowerShell window.

Verify Exchange Online PowerShell connection

Run the Get-EXOMailbox cmdlet. You will see a list of all the mailboxes in Office 365.

PS C:\> Get-EXOMailbox | ft UserPrincipalName,DisplayName

UserPrincipalName        DisplayName
-----------------        -----------
Ali.Tajran@exoip.com     Ali Tajran
Angela.Hart@exoip.com    Angela Hart
Boris.Campbell@exoip.com Boris Campbell
Grace.Rees@exoip.com     Grace Rees
John.Maverick@exoip.com  John Maverick
Kylie.Davidson@exoip.com Kylie Davidson

Disconnect Exchange Online

Be sure to disconnect the remote PowerShell session when you’re finished. If you close the Exchange Online PowerShell Module window without disconnecting the session, you could use up all the remote PowerShell sessions available to you, and you’ll need to wait for the sessions to expire.

Run the Disconnect-ExchangeOnline cmdlet to disconnect the remote PowerShell session.

PS C:\> Disconnect-ExchangeOnline

That’s it!

Read more: Enable MFA Office 365 with PowerShell »

Conclusion

You learned how to connect to Exchange Online PowerShell. First, ensure that the Exchange Online PowerShell module is installed. After that, connect to Exchange Online PowerShell with or without MFA. Don’t forget to disconnect when you finish.

Did you enjoy this article? You may also like Move mailbox to Exchange Online with PowerShell. Don’t forget to follow us and share this article.

ALI TAJRAN

ALI TAJRAN

ALI TAJRAN is a passionate IT Architect, IT Consultant, and Microsoft Certified Trainer. He started Information Technology at a very young age, and his goal is to teach and inspire others. Read more »

This Post Has 0 Comments

Leave a Reply

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