The third-party cloud spam filter is configured, and everything works as expected. Well, you thought…
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.
Table of contents
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 '126.96.36.199' 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 188.8.131.52 -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 email@example.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.
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
Read more: Enable MFA Office 365 with PowerShell »
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.