skip to Main Content

Install Exchange Online PowerShell V2

How to install Exchange Online PowerShell V2 and connect to Exchange Online? A migration is planned for next week. The mailboxes are going to be migrated from on-premises to Exchange Online. We are going to install the new EXO PowerShell V2 module and use it for migrating. I recommend migrating mailboxes with PowerShell instead of the Exchange Admin Center. In this article, you will learn how to install Exchange Online PowerShell V2 module.

Information Exchange Online PowerShell V2 module

The Exchange Online PowerShell V2 module (abbreviated as the EXO V2 module) enables admins to connect to their Exchange Online environment in Microsoft 365 to retrieve data, create new objects, update existing objects, remove objects as well as configure Exchange Online and its features.

The Exchange Online PowerShell V2 module is currently in General Availability (GA). It is stable and ready for use in production environments. This started from version 1.0.1. If you have an older version running, update the EXO V2 module.

Some key points about EXO V2 module:

  • Download from PowerShell gallery
  • Run the module from Windows PowerShell and Windows PowerShell ISE
  • Single cmdlet Connect-ExchangeOnline supports both MFA and non-MFA accounts
  • EXO V2 cmdlets are REST API-based which are much faster and more reliable
  • EXO V2 uses Modern Authentication
  • Older cmdlets are backward compatible

Keep up to date and have a look at the Microsoft website for the release notes.

Install Exchange Online PowerShell V2 module

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

Set ExecutionPolicy

By default, we can’t install scripts. Configure PowerShell to 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 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 get the changes from the previous steps.

Install the module PowerShellGet

Run PowerShell as administrator. Run the command Install-Module PowershellGet -Force. 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 are getting an error that it’s unable to install. Have a read at the article Unable to install NuGet provider for PowerShell.

Run PowerShell as administrator and run the following cmdlet. 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 using Exchange Online PowerShell V2

Do you have MFA enabled on your account? Use option 1. If you don’t have MFA enabled, use option 2.

Option 1: Account with MFA enabled

It’s recommended to have MFA (Multi-Factor Authentication) enabled on the accounts. Connect with your admin account to Exchange Online. Run the cmdlet.

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

After running the cmdlet, the sign-in window shows up. Fill in your password and click Sign in.

Install Exchange Online PowerShell V2 enter password

In the verification window that opens, enter the verification code, and then click Verify.

Install Exchange Online PowerShell V2 enter MFA

You will get back to the PowerShell window and it’s showing the new cmdlets in a banner.

----------------------------------------------------------------------------
We have released new management cmdlets which are faster and more reliable.

|--------------------------------------------------------------------------|
|    Old Cmdlets                    |    New/Reliable/Faster Cmdlets       |
|--------------------------------------------------------------------------|
|    Get-CASMailbox                 |    Get-EXOCASMailbox                 |
|    Get-Mailbox                    |    Get-EXOMailbox                    |
|    Get-MailboxFolderPermission    |    Get-EXOMailboxFolderPermission    |
|    Get-MailboxFolderStatistics    |    Get-EXOMailboxFolderStatistics    |
|    Get-MailboxPermission          |    Get-EXOMailboxPermission          |
|    Get-MailboxStatistics          |    Get-EXOMailboxStatistics          |
|    Get-MobileDeviceStatistics     |    Get-EXOMobileDeviceStatistics     |
|    Get-Recipient                  |    Get-EXORecipient                  |
|    Get-RecipientPermission        |    Get-EXORecipientPermission        |
|--------------------------------------------------------------------------|

To get additional information, run: Get-Help Connect-ExchangeOnline
Please send your feedback and suggestions to exocmdletpreview@service.microsoft.com
----------------------------------------------------------------------------

PS C:\>

Option 2: Account without MFA enabled

Run the following cmdlet.

PS C:\> $UserCredential = Get-Credential

Enter credentials and click OK.

Install Exchange Online PowerShell V2 enter credentials

Connect to Exchange Online by running the cmdlet. This time you will not get another window asking to enter your code (MFA).

PS C:\> Connect-ExchangeOnline -Credential $UserCredential

Now we are connected to Exchange Online and ready to type in the new cmdlets.

Exchange Online PowerShell V2 new cmdlets

See the list of new and old cmdlets.

Good to know

If you don’t want to show the screen output when connecting to Exchange Online, make use of the -ShowBanner switch. This will hide the banner as seen above.

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

Sign out from Exchange Online

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.

This cmdlet is the V2 equivalent of Get-PSSession | Remove-PSSession. In addition to cleaning up session object and local files, it also removes the access token from cache, which is used for authenticating against V2 cmdlets.

PS C:\> Disconnect-ExchangeOnline

Running this cmdlet clears all active sessions created using Connect-ExchangeOnline or Connect-IPPSSession.
Press(Y/y/A/a) if you want to continue.
[Y] Yes  [A] Yes to All  [N] No  [L] No to All  [S] Suspend  [?] Help (default is "Y"): Y
Removed the PSSesion ExchangeOnlineInternalSession_2 connected to outlook.office365.com
Disconnected successfully !

Connect to Exchange Online PowerShell

Do you like to know how to connect to Exchange Online PowerShell without using version 2? Read the articles that we already have covered for you.

Conclusion

In this article, you learned how to install Exchange Online PowerShell V2. There are two options to connect to Exchange Online with Exchange Online PowerShell V2. That’s with MFA enabled or without MFA enabled. After connecting to EXO, you can make use of the new cmdlets.

If you liked this article, you may also like to read Get mailbox permissions with PowerShell. Follow us on Twitter and LinkedIn to stay up to date with the latest articles.

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 7 Comments

  1. It’s like they try and make it as convoluted and unintuitive as possible. “Here’s a 17 step process to access features that really should be available in the portal, but aren’t”

  2. Do you know where I can find the module?

    The Gallery site has been down for days… 🙁

    Thanks

Leave a Reply

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

Back To Top